The problem/use-case that the feature addresses

Currently, Lua scripts only supports ARGS that are passed in by position. When dealing with scripts that receive multiple parameters it would be helpful to have named arguments.

Description of the feature

A module similar to "click" module in python for easy parsing of command line arguments. The lua script will receive these as an associative table with the keys being the argument name.

Alternatives you've considered

Write custom lua code for parsing command line named arguments: Trying to include "--" in the arguments from redis-cli results in "Unrecognized option or bad number of args for: '--test'". Also, since includes are not possible without a preprocessor this would make for a lot of repeated code. A python plugin exists that enables a preprocessed script tag of %arg. This is close to the required solution but is Python specific and not included as part of the script Preprocessing to add custom code to parse the args, similar to "Click" module for python

Comment From: madolson

Unfortunately it will be hard to change the syntax of the EVAL command at this point. It seems like this could be implemented in your client code, replacing some placeholder with the actual positional key, like a pre-processor before being sent to Redis.

Comment From: oranagra

I agree we can't add this feature to EVAL as it is today, but i do think we we may want to do some major face-lift for scripting one day. It would be nice for scripts to able able to take both positional arguments (like they do today), and named arguments too. kinda like Python's args and kwargs, which would mean that a script can have default values for arguments that are missing.

one way could be for example to make a new EVAL command take 4 arguments, like: EVAL2 <key-count> <named-key-count> <arg-count> <named-arg-count> ... then the script itself had the two existing arrays: KEYS[i] and ARGV[i], and also two new maps: NKEYS[<name>] and NARGS[<name>].

so imagine this call: EVAL2 <script> 0 2 1 1 src mysrc dst mydst posarg_value optional_arg optional_value i.e. there are no positional key args. src and dst are named key arguments. postarg_value is positional argument, and optional_arg is named argument. and the script can check if the map doesn't contain optional_arg and use a default value instead.

@MeirShpilraien @yossigo FYI.

Comment From: madolson

We can talk about this more, but I think that unnecessarily complicates the arguments to EVAL. I think it's more compelling to have available in python than it does for Redis, since you can build a hash and then dump that into the arguments of something. We don't really have that notion in Redis.

I suppose my main argument is that I think it'll just be complex, even your example isn't the easiest to follow, so if we had a good simple syntax I would be okay with it.

Comment From: MeirShpilraien

We currently decided not to tackle this issue as part of Redis Functions for few reasons: 1. Named keys are problematic, you can not have default values for key names (will cause problems on cluster mode). This reduces from the flexibility that this feature will give to the user. 2. We do not have a good enough command key-spec that will allow to specify positional keys, named keys, positional arguments and named argument. We can introduce a new one but it feels like an overkill. 3. Named arguments (not named keys) can be achieve today on the script level with a very small efforts.

We believe that this can be handled with proper tooling that will allow easy arguments parsing and can be handled by each engine separately.

If there is any objection please write a comment.