redis-server command line arguments support take one bulk string with spaces for MULTI_ARG configs parsing. And allow options value to use the -- prefix#10660
Conversation
… spaces for MULTI_ARG configs parsing Currently redis-server looks for arguments that start with `--`, and anything in between them is considered arguments for the config. like: `src/redis-server --shutdown-on-sigint nosave force now --port 6380` MULTI_ARG configs behave differently for CONFIG command, vs the command line argument for redis-server. i.e. CONFIG command takes one bulk string with spaces in it, while the command line takes an argv array with multiple values. In this PR, in config.c, if `argc > 1` we can take them as is, and if the config is a `MULTI_ARG` and `argc == 1`, we will split it by spaces. So both of these will be the same: ``` redis-server --shutdown-on-sigint nosave force now --port 6380 redis-server --shutdown-on-sigint "nosave force now" --port 6380 ``` And for MULTI_ARG, now we will check that it has at least one arg, we can return `wrong number of arguments` before `config->interface.set`. ``` old: src/redis-server --shutdown-on-sigint >>> 'shutdown-on-sigint' argument(s) must be one of the following: default, save, nosave, now, force new: src/redis-server --shutdown-on-sigint >>> 'shutdown-on-sigint' wrong number of arguments ``` This is mentioned in redis#10594 (comment) Co-authored-by: Oran Agra <[email protected]>
|
@enjoy-binbin thank you. what i did want to handle is the config matching in server.c. |
|
I don't like |
|
@oranagra I misunderstood what you want before (like i did try Now with the new code, the result is: |
oranagra
left a comment
There was a problem hiding this comment.
LGTM.
@yoav-steinberg @yossigo @madolson PTAL
Co-authored-by: yoav-steinberg <[email protected]>
Allow option value to use `--` prefix will be a breaking change, will break: src/redis-server --save --loglevel verbose It used to work the same as: src/redis-server --save "" --loglevel verbose revert it
oranagra
left a comment
There was a problem hiding this comment.
ohh, took down some of these notes hours ago, now i realize i forgot to post them.
save "", sdssplitargs(argv[1], &new_argc) the new_argc will become 0, and will break save ""
Co-authored-by: Oran Agra <[email protected]>
|
@redis/core-team please approve or comment (note the breaking change). |
…ue in the same arg (#10866) This commit has two topics. ## Passing config name and value in the same arg In #10660 (Redis 7.0.1), when we supported the config values that can start with `--` prefix (one of the two topics of that PR), we broke another pattern: `redis-server redis.config "name value"`, passing both config name and it's value in the same arg, see #10865 This wasn't a intended change (i.e we didn't realize this pattern used to work). Although this is a wrong usage, we still like to fix it. Now we support something like: ``` src/redis-server redis.conf "--maxmemory '700mb'" "--maxmemory-policy volatile-lru" --proc-title-template --my--title--template --loglevel verbose ``` ## Changes around --save Also in this PR, we undo the breaking change we made in #10660 on purpose. 1. `redis-server redis.conf --save --loglevel verbose` (missing `save` argument before anotehr argument). In 7.0.1, it was throwing an wrong arg error. Now it will work and reset the save, similar to how it used to be in 7.0.0 and 6.2.x. 3. `redis-server redis.conf --loglevel verbose --save` (missing `save` argument as last argument). In 6.2, it did not reset the save, which was a bug (inconsistent with the previous bullet). Now we will make it work and reset the save as well (a bug fix).
There is a issue with --sentinel: ``` [root]# src/redis-server sentinel.conf --sentinel --loglevel verbose *** FATAL CONFIG FILE ERROR (Redis 255.255.255) *** Reading the configuration file, at line 352 >>> 'sentinel "--loglevel" "verbose"' Unrecognized sentinel configuration statement ``` This is because in redis#10660 (Redis 7.0.1), `--` prefix change break it. In this PR, we will handle `--sentinel` the same as we did for `--save` in redis#10866. i.e. it's a pseudo config option with no value. Fixes redis#11586. Co-authored-by: Oran Agra <[email protected]>
There is a issue with --sentinel: ``` [root]# src/redis-server sentinel.conf --sentinel --loglevel verbose *** FATAL CONFIG FILE ERROR (Redis 255.255.255) *** Reading the configuration file, at line 352 >>> 'sentinel "--loglevel" "verbose"' Unrecognized sentinel configuration statement ``` This is because in #10660 (Redis 7.0.1), `--` prefix change break it. In this PR, we will handle `--sentinel` the same as we did for `--save` in #10866. i.e. it's a pseudo config option with no value.
There is a issue with --sentinel: ``` [root]# src/redis-server sentinel.conf --sentinel --loglevel verbose *** FATAL CONFIG FILE ERROR (Redis 255.255.255) *** Reading the configuration file, at line 352 >>> 'sentinel "--loglevel" "verbose"' Unrecognized sentinel configuration statement ``` This is because in #10660 (Redis 7.0.1), `--` prefix change break it. In this PR, we will handle `--sentinel` the same as we did for `--save` in #10866. i.e. it's a pseudo config option with no value. (cherry picked from commit 8f13ac1)
There is a issue with --sentinel: ``` [root]# src/redis-server sentinel.conf --sentinel --loglevel verbose *** FATAL CONFIG FILE ERROR (Redis 255.255.255) *** Reading the configuration file, at line 352 >>> 'sentinel "--loglevel" "verbose"' Unrecognized sentinel configuration statement ``` This is because in redis#10660 (Redis 7.0.1), `--` prefix change break it. In this PR, we will handle `--sentinel` the same as we did for `--save` in redis#10866. i.e. it's a pseudo config option with no value.
… spaces for MULTI_ARG configs parsing. And allow options value to use the -- prefix (redis#10660) ## Take one bulk string with spaces for MULTI_ARG configs parsing Currently redis-server looks for arguments that start with `--`, and anything in between them is considered arguments for the config. like: `src/redis-server --shutdown-on-sigint nosave force now --port 6380` MULTI_ARG configs behave differently for CONFIG command, vs the command line argument for redis-server. i.e. CONFIG command takes one bulk string with spaces in it, while the command line takes an argv array with multiple values. In this PR, in config.c, if `argc > 1` we can take them as is, and if the config is a `MULTI_ARG` and `argc == 1`, we will split it by spaces. So both of these will be the same: ``` redis-server --shutdown-on-sigint nosave force now --shutdown-on-sigterm nosave force redis-server --shutdown-on-sigint nosave "force now" --shutdown-on-sigterm nosave force redis-server --shutdown-on-sigint nosave "force now" --shutdown-on-sigterm "nosave force" ``` ## Allow options value to use the `--` prefix Currently it decides to switch to the next config, as soon as it sees `--`, even if there was not a single value provided yet to the last config, this makes it impossible to define a config value that has `--` prefix in it. For instance, if we want to set the logfile to `--my--log--file`, like `redis-server --logfile --my--log--file --loglevel verbose`, current code will handle that incorrectly. In this PR, now we allow a config value that has `--` prefix in it. **But note that** something like `redis-server --some-config --config-value1 --config-value2 --loglevel debug` would not work, because if you want to pass a value to a config starting with `--`, it can only be a single value. like: `redis-server --some-config "--config-value1 --config-value2" --loglevel debug` An example (using `--` prefix config value): ``` redis-server --logfile --my--log--file --loglevel verbose redis-cli config get logfile loglevel 1) "loglevel" 2) "verbose" 3) "logfile" 4) "--my--log--file" ``` ### Potentially breaking change `redis-server --save --loglevel verbose` used to work the same as `redis-server --save "" --loglevel verbose` now, it'll error!
…ue in the same arg (redis#10866) This commit has two topics. ## Passing config name and value in the same arg In redis#10660 (Redis 7.0.1), when we supported the config values that can start with `--` prefix (one of the two topics of that PR), we broke another pattern: `redis-server redis.config "name value"`, passing both config name and it's value in the same arg, see redis#10865 This wasn't a intended change (i.e we didn't realize this pattern used to work). Although this is a wrong usage, we still like to fix it. Now we support something like: ``` src/redis-server redis.conf "--maxmemory '700mb'" "--maxmemory-policy volatile-lru" --proc-title-template --my--title--template --loglevel verbose ``` ## Changes around --save Also in this PR, we undo the breaking change we made in redis#10660 on purpose. 1. `redis-server redis.conf --save --loglevel verbose` (missing `save` argument before anotehr argument). In 7.0.1, it was throwing an wrong arg error. Now it will work and reset the save, similar to how it used to be in 7.0.0 and 6.2.x. 3. `redis-server redis.conf --loglevel verbose --save` (missing `save` argument as last argument). In 6.2, it did not reset the save, which was a bug (inconsistent with the previous bullet). Now we will make it work and reset the save as well (a bug fix).
There is a issue with --sentinel: ``` [root]# src/redis-server sentinel.conf --sentinel --loglevel verbose *** FATAL CONFIG FILE ERROR (Redis 255.255.255) *** Reading the configuration file, at line 352 >>> 'sentinel "--loglevel" "verbose"' Unrecognized sentinel configuration statement ``` This is because in redis#10660 (Redis 7.0.1), `--` prefix change break it. In this PR, we will handle `--sentinel` the same as we did for `--save` in redis#10866. i.e. it's a pseudo config option with no value.
Take one bulk string with spaces for MULTI_ARG configs parsing
Currently redis-server looks for arguments that start with
--,and anything in between them is considered arguments for the config.
like:
src/redis-server --shutdown-on-sigint nosave force now --port 6380MULTI_ARG configs behave differently for CONFIG command, vs the command
line argument for redis-server.
i.e. CONFIG command takes one bulk string with spaces in it, while the
command line takes an argv array with multiple values.
In this PR, in config.c, if
argc > 1we can take them as is,and if the config is a
MULTI_ARGandargc == 1, we will split it by spaces.So both of these will be the same:
Allow options value to use the
--prefixCurrently it decides to switch to the next config, as soon as it sees
--,even if there was not a single value provided yet to the last config,
this makes it impossible to define a config value that has
--prefix in it.For instance, if we want to set the logfile to
--my--log--file,like
redis-server --logfile --my--log--file --loglevel verbose,current code will handle that incorrectly.
In this PR, now we allow a config value that has
--prefix in it.But note that something like
redis-server --some-config --config-value1 --config-value2 --loglevel debugwould not work, because if you want to pass a value to a config starting with
--, it can only be a single value.like:
redis-server --some-config "--config-value1 --config-value2" --loglevel debugAn example (using
--prefix config value):This is mentioned in #10594 (comment)
Potentially breaking change
redis-server --save --loglevel verboseused to work the same asredis-server --save "" --loglevel verbosenow, it'll error!
Note that this breaking change was undo in #10866 (7.0.3)