The problem/use-case that the feature addresses

I am testing the redis-protobuf module, which needs to pass the directory of the .proto file through the --DIR parameter.

When started via redis.conf, everything is ok.

################################# MODULES ############## #####################

# Load modules at startup. If the server is not able to load modules
# it will abort. It is possible to use multiple loadmodule directives.
#
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so
loadmodule /Users/yangbodong/git/redis/redis-modules/src/modules/redis-protobuf/compile/libredis-protobuf.dylib --DIR /Users/yangbodong/git/redis/redis-modules/src/modules/redis -protobuf/proto-directory
...

but when i use command line to start, i failed.

./src/redis-server --loadmodule /Users/yangbodong/git/redis/redis-modules/src/modules/redis-protobuf/compile/libredis-protobuf.dylib --DIR /Users/yangbodong/git/redis/redis-modules/src/modules/redis-protobuf/proto-directory


93352:M 03 Jun 2021 11:18:02.980 # Server initialized
93352:M 03 Jun 2021 11:18:02.996 # <PB> option '--DIR dir' is required
93352:M 03 Jun 2021 11:18:02.996 # Module /Users/yangbodong/git/redis/redis-modules/src/modules/redis-protobuf/compile/libredis-protobuf.dylib initialization failed. Module not loaded
93352:M 03 Jun 2021 11:18:02.996 # Can't load module from /Users/yangbodong/git/redis/redis-modules/src/modules/redis-protobuf/compile/libredis-protobuf.dylib: server aborting

The problem is that when the module parameter (beginning with --) is passed through the command line, it is recognized as a Redis parameter, If we do not pass the -- parameter, although DIR can be passed to the module, the module still cannot be correctly identified, that is, the following method is also wrong (note: DIR not --DIR):

./src/redis-server --loadmodule /Users/yangbodong/git/redis/redis-modules/src/modules/redis-protobuf/compile/libredis-protobuf.dylib DIR /Users/yangbodong/git/redis/redis-modules/src/modules/redis-protobuf/proto-directory

Description of the feature

A way which pass parameters to module through command line options.

the current redis parameter transfer method is as follows, may be we can use ** to pass module parameters.

!= - : config file
- : read form stdin
-- : redis option
** : pass to module
diff --git a/src/server.c b/src/server.c
index 95202f9fa..57e2c3772 100644
--- a/src/server.c
+++ b/src/server.c
@@ -6287,6 +6287,10 @@ int main(int argc, char **argv) {
                 if (sdslen(options)) options = sdscat(options,"\n");
                 options = sdscat(options,argv[j]+2);
                 options = sdscat(options," ");
+            } else if (argv[j][0] == '*' && argv[j][1] == '*') {
+                /* Module argument */
+                options = sdscatrepr(options,argv[j]+2,strlen(argv[j])-2);
+                options = sdscat(options," ");
             } else {
                 /* Option argument */
                 options = sdscatrepr(options,argv[j],strlen(argv[j]));

so, we can start as (**--DIR ):

./src/redis-serve --loadmodule /Users/yangbodong/git/redis/redis-modules/src/modules/redis-protobuf/compile/libredis-protobuf.dylib **--DIR /Users/yangbodong/git/redis/redis-modules/src/modules/redis-protobuf/proto-directory


93706:M 03 Jun 2021 11:32:01.604 # Server initialized
93706:M 03 Jun 2021 11:32:01.625 * Module 'PB' loaded from /Users/yangbodong/git/redis/redis-modules/src/modules/redis-protobuf/compile/libredis-protobuf.dylib
93706:M 03 Jun 2021 11:32:01.625 * Loading RDB produced by version 255.255.255
93706:M 03 Jun 2021 11:32:01.625 * RDB age 4744 seconds
93706:M 03 Jun 2021 11:32:01.625 * RDB memory usage when created 0.97 Mb
93706:M 03 Jun 2021 11:32:01.625 * DB loaded from disk: 0.000 seconds
93706:M 03 Jun 2021 11:32:01.625 * Ready to accept connections

Comment From: yossigo

@yangbodong22011 I tend to say this is a module issue. Most other modules accept their arguments without a -- prefix (i.e. redis-server --loadmodule libredis-protobuf.dylib dir /my/dir --next-arg) so this is not an issue.

Comment From: yangbodong22011

@yossigo Yes, you are right, but - and -- are the most common prefixes for passing parameters. In addition to redis-protobuf, other prefixes may also be used in this way. Therefore, we'd better provide an independent method for passing module parameters, **--DIR is just my primary idea, and it's not elegant. We can discuss it. But if you insist that this is not a problem, I can accept it.

Comment From: yossigo

@yangbodong22011 This convention is common for passing arguments to POSIX binaries, I don't think we should automatically assume it applies to the Redis module ecosystem. Perhaps we should do a better job of describing and documenting how well behaved modules are expected to work because maybe not all module authors are aware of these intrinsics.

Comment From: yangbodong22011

Perhaps we should do a better job of describing and documenting how well behaved modules are expected to work because maybe not all module authors are aware of these intrinsics.

@yossigo Agree, let us add documentation to describe how to correctly pass parameters to the module. - Try to avoid using -- - If it must be used, it cannot be started by command line startup, but you can use redis.conf or MODULE LOAD command to load module

Should we update this document? https://github.com/redis/redis-doc/blob/master/topics/modules-intro.md @itamarhaber ping