2018-09-30 04:37:19 -04:00
|
|
|
proc cmdstat {cmd} {
|
2020-10-08 01:33:17 -04:00
|
|
|
return [cmdrstat $cmd r]
|
2018-09-30 04:37:19 -04:00
|
|
|
}
|
|
|
|
|
2023-02-23 02:07:49 -05:00
|
|
|
proc getlru {key} {
|
|
|
|
set objinfo [r debug object $key]
|
|
|
|
foreach info $objinfo {
|
|
|
|
set kvinfo [split $info ":"]
|
|
|
|
if {[string compare [lindex $kvinfo 0] "lru"] == 0} {
|
|
|
|
return [lindex $kvinfo 1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fail "Can't get LRU info with DEBUG OBJECT"
|
|
|
|
}
|
|
|
|
|
2016-06-15 11:15:18 -04:00
|
|
|
start_server {tags {"introspection"}} {
|
2022-10-09 11:02:37 -04:00
|
|
|
test {The microsecond part of the TIME command will not overflow} {
|
|
|
|
set now [r time]
|
|
|
|
set microseconds [lindex $now 1]
|
|
|
|
assert_morethan $microseconds 0
|
|
|
|
assert_lessthan $microseconds 1000000
|
|
|
|
}
|
|
|
|
|
2020-11-18 04:16:21 -05:00
|
|
|
test {TTL, TYPE and EXISTS do not alter the last access time of a key} {
|
2016-06-15 11:15:18 -04:00
|
|
|
r set foo bar
|
|
|
|
after 3000
|
|
|
|
r ttl foo
|
|
|
|
r type foo
|
2020-11-18 04:16:21 -05:00
|
|
|
r exists foo
|
2016-06-15 11:15:18 -04:00
|
|
|
assert {[r object idletime foo] >= 2}
|
|
|
|
}
|
|
|
|
|
|
|
|
test {TOUCH alters the last access time of a key} {
|
|
|
|
r set foo bar
|
|
|
|
after 3000
|
|
|
|
r touch foo
|
|
|
|
assert {[r object idletime foo] < 2}
|
|
|
|
}
|
|
|
|
|
2023-02-23 02:07:49 -05:00
|
|
|
test {Operations in no-touch mode do not alter the last access time of a key} {
|
|
|
|
r set foo bar
|
|
|
|
r client no-touch on
|
|
|
|
set oldlru [getlru foo]
|
2023-03-07 08:27:09 -05:00
|
|
|
after 1100
|
2023-02-23 02:07:49 -05:00
|
|
|
r get foo
|
|
|
|
set newlru [getlru foo]
|
|
|
|
assert_equal $newlru $oldlru
|
|
|
|
r client no-touch off
|
|
|
|
r get foo
|
|
|
|
set newlru [getlru foo]
|
|
|
|
assert_morethan $newlru $oldlru
|
|
|
|
} {} {needs:debug}
|
|
|
|
|
2016-06-15 11:15:18 -04:00
|
|
|
test {TOUCH returns the number of existing keys specified} {
|
|
|
|
r flushdb
|
2021-06-09 08:13:24 -04:00
|
|
|
r set key1{t} 1
|
|
|
|
r set key2{t} 2
|
|
|
|
r touch key0{t} key1{t} key2{t} key3{t}
|
2016-06-15 11:15:18 -04:00
|
|
|
} 2
|
2018-09-30 04:37:19 -04:00
|
|
|
|
|
|
|
test {command stats for GEOADD} {
|
|
|
|
r config resetstat
|
|
|
|
r GEOADD foo 0 0 bar
|
|
|
|
assert_match {*calls=1,*} [cmdstat geoadd]
|
|
|
|
assert_match {} [cmdstat zadd]
|
2021-06-09 08:13:24 -04:00
|
|
|
} {} {needs:config-resetstat}
|
2018-09-30 04:37:19 -04:00
|
|
|
|
Sort out the mess around Lua error messages and error stats (#10329)
This PR fix 2 issues on Lua scripting:
* Server error reply statistics (some errors were counted twice).
* Error code and error strings returning from scripts (error code was missing / misplaced).
## Statistics
a Lua script user is considered part of the user application, a sophisticated transaction,
so we want to count an error even if handled silently by the script, but when it is
propagated outwards from the script we don't wanna count it twice. on the other hand,
if the script decides to throw an error on its own (using `redis.error_reply`), we wanna
count that too.
Besides, we do count the `calls` in command statistics for the commands the script calls,
we we should certainly also count `failed_calls`.
So when a simple `eval "return redis.call('set','x','y')" 0` fails, it should count the failed call
to both SET and EVAL, but the `errorstats` and `total_error_replies` should be counted only once.
The PR changes the error object that is raised on errors. Instead of raising a simple Lua
string, Redis will raise a Lua table in the following format:
```
{
err='<error message (including error code)>',
source='<User source file name>',
line='<line where the error happned>',
ignore_error_stats_update=true/false,
}
```
The `luaPushError` function was modified to construct the new error table as describe above.
The `luaRaiseError` was renamed to `luaError` and is now simply called `lua_error` to raise
the table on the top of the Lua stack as the error object.
The reason is that since its functionality is changed, in case some Redis branch / fork uses it,
it's better to have a compilation error than a bug.
The `source` and `line` fields are enriched by the error handler (if possible) and the
`ignore_error_stats_update` is optional and if its not present then the default value is `false`.
If `ignore_error_stats_update` is true, the error will not be counted on the error stats.
When parsing Redis call reply, each error is translated to a Lua table on the format describe
above and the `ignore_error_stats_update` field is set to `true` so we will not count errors
twice (we counted this error when we invoke the command).
The changes in this PR might have been considered as a breaking change for users that used
Lua `pcall` function. Before, the error was a string and now its a table. To keep backward
comparability the PR override the `pcall` implementation and extract the error message from
the error table and return it.
Example of the error stats update:
```
127.0.0.1:6379> lpush l 1
(integer) 2
127.0.0.1:6379> eval "return redis.call('get', 'l')" 0
(error) WRONGTYPE Operation against a key holding the wrong kind of value. script: e471b73f1ef44774987ab00bdf51f21fd9f7974a, on @user_script:1.
127.0.0.1:6379> info Errorstats
# Errorstats
errorstat_WRONGTYPE:count=1
127.0.0.1:6379> info commandstats
# Commandstats
cmdstat_eval:calls=1,usec=341,usec_per_call=341.00,rejected_calls=0,failed_calls=1
cmdstat_info:calls=1,usec=35,usec_per_call=35.00,rejected_calls=0,failed_calls=0
cmdstat_lpush:calls=1,usec=14,usec_per_call=14.00,rejected_calls=0,failed_calls=0
cmdstat_get:calls=1,usec=10,usec_per_call=10.00,rejected_calls=0,failed_calls=1
```
## error message
We can now construct the error message (sent as a reply to the user) from the error table,
so this solves issues where the error message was malformed and the error code appeared
in the middle of the error message:
```diff
127.0.0.1:6379> eval "return redis.call('set','x','y')" 0
-(error) ERR Error running script (call to 71e6319f97b0fe8bdfa1c5df3ce4489946dda479): @user_script:1: OOM command not allowed when used memory > 'maxmemory'.
+(error) OOM command not allowed when used memory > 'maxmemory' @user_script:1. Error running script (call to 71e6319f97b0fe8bdfa1c5df3ce4489946dda479)
```
```diff
127.0.0.1:6379> eval "redis.call('get', 'l')" 0
-(error) ERR Error running script (call to f_8a705cfb9fb09515bfe57ca2bd84a5caee2cbbd1): @user_script:1: WRONGTYPE Operation against a key holding the wrong kind of value
+(error) WRONGTYPE Operation against a key holding the wrong kind of value script: 8a705cfb9fb09515bfe57ca2bd84a5caee2cbbd1, on @user_script:1.
```
Notica that `redis.pcall` was not change:
```
127.0.0.1:6379> eval "return redis.pcall('get', 'l')" 0
(error) WRONGTYPE Operation against a key holding the wrong kind of value
```
## other notes
Notice that Some commands (like GEOADD) changes the cmd variable on the client stats so we
can not count on it to update the command stats. In order to be able to update those stats correctly
we needed to promote `realcmd` variable to be located on the client struct.
Tests was added and modified to verify the changes.
Related PR's: #10279, #10218, #10278, #10309
Co-authored-by: Oran Agra <oran@redislabs.com>
2022-02-27 06:40:57 -05:00
|
|
|
test {errors stats for GEOADD} {
|
|
|
|
r config resetstat
|
|
|
|
# make sure geo command will failed
|
|
|
|
r set foo 1
|
|
|
|
assert_error {WRONGTYPE Operation against a key holding the wrong kind of value*} {r GEOADD foo 0 0 bar}
|
|
|
|
assert_match {*calls=1*,rejected_calls=0,failed_calls=1*} [cmdstat geoadd]
|
|
|
|
assert_match {} [cmdstat zadd]
|
|
|
|
} {} {needs:config-resetstat}
|
|
|
|
|
2018-09-30 04:37:19 -04:00
|
|
|
test {command stats for EXPIRE} {
|
|
|
|
r config resetstat
|
|
|
|
r SET foo bar
|
|
|
|
r EXPIRE foo 0
|
|
|
|
assert_match {*calls=1,*} [cmdstat expire]
|
|
|
|
assert_match {} [cmdstat del]
|
2021-06-09 08:13:24 -04:00
|
|
|
} {} {needs:config-resetstat}
|
2018-09-30 04:37:19 -04:00
|
|
|
|
|
|
|
test {command stats for BRPOP} {
|
|
|
|
r config resetstat
|
|
|
|
r LPUSH list foo
|
|
|
|
r BRPOP list 0
|
|
|
|
assert_match {*calls=1,*} [cmdstat brpop]
|
|
|
|
assert_match {} [cmdstat rpop]
|
2021-06-09 08:13:24 -04:00
|
|
|
} {} {needs:config-resetstat}
|
2018-09-30 04:37:19 -04:00
|
|
|
|
|
|
|
test {command stats for MULTI} {
|
|
|
|
r config resetstat
|
|
|
|
r MULTI
|
2021-06-09 08:13:24 -04:00
|
|
|
r set foo{t} bar
|
|
|
|
r GEOADD foo2{t} 0 0 bar
|
|
|
|
r EXPIRE foo2{t} 0
|
2018-09-30 04:37:19 -04:00
|
|
|
r EXEC
|
|
|
|
assert_match {*calls=1,*} [cmdstat multi]
|
|
|
|
assert_match {*calls=1,*} [cmdstat exec]
|
|
|
|
assert_match {*calls=1,*} [cmdstat set]
|
|
|
|
assert_match {*calls=1,*} [cmdstat expire]
|
|
|
|
assert_match {*calls=1,*} [cmdstat geoadd]
|
2021-06-09 08:13:24 -04:00
|
|
|
} {} {needs:config-resetstat}
|
2018-09-30 04:37:19 -04:00
|
|
|
|
|
|
|
test {command stats for scripts} {
|
|
|
|
r config resetstat
|
|
|
|
r set mykey myval
|
|
|
|
r eval {
|
|
|
|
redis.call('set', KEYS[1], 0)
|
|
|
|
redis.call('expire', KEYS[1], 0)
|
|
|
|
redis.call('geoadd', KEYS[1], 0, 0, "bar")
|
|
|
|
} 1 mykey
|
|
|
|
assert_match {*calls=1,*} [cmdstat eval]
|
|
|
|
assert_match {*calls=2,*} [cmdstat set]
|
|
|
|
assert_match {*calls=1,*} [cmdstat expire]
|
|
|
|
assert_match {*calls=1,*} [cmdstat geoadd]
|
2021-06-09 08:13:24 -04:00
|
|
|
} {} {needs:config-resetstat}
|
Treat subcommands as commands (#9504)
## Intro
The purpose is to allow having different flags/ACL categories for
subcommands (Example: CONFIG GET is ok-loading but CONFIG SET isn't)
We create a small command table for every command that has subcommands
and each subcommand has its own flags, etc. (same as a "regular" command)
This commit also unites the Redis and the Sentinel command tables
## Affected commands
CONFIG
Used to have "admin ok-loading ok-stale no-script"
Changes:
1. Dropped "ok-loading" in all except GET (this doesn't change behavior since
there were checks in the code doing that)
XINFO
Used to have "read-only random"
Changes:
1. Dropped "random" in all except CONSUMERS
XGROUP
Used to have "write use-memory"
Changes:
1. Dropped "use-memory" in all except CREATE and CREATECONSUMER
COMMAND
No changes.
MEMORY
Used to have "random read-only"
Changes:
1. Dropped "random" in PURGE and USAGE
ACL
Used to have "admin no-script ok-loading ok-stale"
Changes:
1. Dropped "admin" in WHOAMI, GENPASS, and CAT
LATENCY
No changes.
MODULE
No changes.
SLOWLOG
Used to have "admin random ok-loading ok-stale"
Changes:
1. Dropped "random" in RESET
OBJECT
Used to have "read-only random"
Changes:
1. Dropped "random" in ENCODING and REFCOUNT
SCRIPT
Used to have "may-replicate no-script"
Changes:
1. Dropped "may-replicate" in all except FLUSH and LOAD
CLIENT
Used to have "admin no-script random ok-loading ok-stale"
Changes:
1. Dropped "random" in all except INFO and LIST
2. Dropped "admin" in ID, TRACKING, CACHING, GETREDIR, INFO, SETNAME, GETNAME, and REPLY
STRALGO
No changes.
PUBSUB
No changes.
CLUSTER
Changes:
1. Dropped "admin in countkeysinslots, getkeysinslot, info, nodes, keyslot, myid, and slots
SENTINEL
No changes.
(note that DEBUG also fits, but we decided not to convert it since it's for
debugging and anyway undocumented)
## New sub-command
This commit adds another element to the per-command output of COMMAND,
describing the list of subcommands, if any (in the same structure as "regular" commands)
Also, it adds a new subcommand:
```
COMMAND LIST [FILTERBY (MODULE <module-name>|ACLCAT <cat>|PATTERN <pattern>)]
```
which returns a set of all commands (unless filters), but excluding subcommands.
## Module API
A new module API, RM_CreateSubcommand, was added, in order to allow
module writer to define subcommands
## ACL changes:
1. Now, that each subcommand is actually a command, each has its own ACL id.
2. The old mechanism of allowed_subcommands is redundant
(blocking/allowing a subcommand is the same as blocking/allowing a regular command),
but we had to keep it, to support the widespread usage of allowed_subcommands
to block commands with certain args, that aren't subcommands (e.g. "-select +select|0").
3. I have renamed allowed_subcommands to allowed_firstargs to emphasize the difference.
4. Because subcommands are commands in ACL too, you can now use "-" to block subcommands
(e.g. "+client -client|kill"), which wasn't possible in the past.
5. It is also possible to use the allowed_firstargs mechanism with subcommand.
For example: `+config -config|set +config|set|loglevel` will block all CONFIG SET except
for setting the log level.
6. All of the ACL changes above required some amount of refactoring.
## Misc
1. There are two approaches: Either each subcommand has its own function or all
subcommands use the same function, determining what to do according to argv[0].
For now, I took the former approaches only with CONFIG and COMMAND,
while other commands use the latter approach (for smaller blamelog diff).
2. Deleted memoryGetKeys: It is no longer needed because MEMORY USAGE now uses the "range" key spec.
4. Bugfix: GETNAME was missing from CLIENT's help message.
5. Sentinel and Redis now use the same table, with the same function pointer.
Some commands have a different implementation in Sentinel, so we redirect
them (these are ROLE, PUBLISH, and INFO).
6. Command stats now show the stats per subcommand (e.g. instead of stats just
for "config" you will have stats for "config|set", "config|get", etc.)
7. It is now possible to use COMMAND directly on subcommands:
COMMAND INFO CONFIG|GET (The pipeline syntax was inspired from ACL, and
can be used in functions lookupCommandBySds and lookupCommandByCString)
8. STRALGO is now a container command (has "help")
## Breaking changes:
1. Command stats now show the stats per subcommand (see (5) above)
2021-10-20 04:52:57 -04:00
|
|
|
|
2023-03-26 01:39:04 -04:00
|
|
|
test {COMMAND COUNT get total number of Redis commands} {
|
|
|
|
assert_morethan [r command count] 0
|
|
|
|
}
|
|
|
|
|
Treat subcommands as commands (#9504)
## Intro
The purpose is to allow having different flags/ACL categories for
subcommands (Example: CONFIG GET is ok-loading but CONFIG SET isn't)
We create a small command table for every command that has subcommands
and each subcommand has its own flags, etc. (same as a "regular" command)
This commit also unites the Redis and the Sentinel command tables
## Affected commands
CONFIG
Used to have "admin ok-loading ok-stale no-script"
Changes:
1. Dropped "ok-loading" in all except GET (this doesn't change behavior since
there were checks in the code doing that)
XINFO
Used to have "read-only random"
Changes:
1. Dropped "random" in all except CONSUMERS
XGROUP
Used to have "write use-memory"
Changes:
1. Dropped "use-memory" in all except CREATE and CREATECONSUMER
COMMAND
No changes.
MEMORY
Used to have "random read-only"
Changes:
1. Dropped "random" in PURGE and USAGE
ACL
Used to have "admin no-script ok-loading ok-stale"
Changes:
1. Dropped "admin" in WHOAMI, GENPASS, and CAT
LATENCY
No changes.
MODULE
No changes.
SLOWLOG
Used to have "admin random ok-loading ok-stale"
Changes:
1. Dropped "random" in RESET
OBJECT
Used to have "read-only random"
Changes:
1. Dropped "random" in ENCODING and REFCOUNT
SCRIPT
Used to have "may-replicate no-script"
Changes:
1. Dropped "may-replicate" in all except FLUSH and LOAD
CLIENT
Used to have "admin no-script random ok-loading ok-stale"
Changes:
1. Dropped "random" in all except INFO and LIST
2. Dropped "admin" in ID, TRACKING, CACHING, GETREDIR, INFO, SETNAME, GETNAME, and REPLY
STRALGO
No changes.
PUBSUB
No changes.
CLUSTER
Changes:
1. Dropped "admin in countkeysinslots, getkeysinslot, info, nodes, keyslot, myid, and slots
SENTINEL
No changes.
(note that DEBUG also fits, but we decided not to convert it since it's for
debugging and anyway undocumented)
## New sub-command
This commit adds another element to the per-command output of COMMAND,
describing the list of subcommands, if any (in the same structure as "regular" commands)
Also, it adds a new subcommand:
```
COMMAND LIST [FILTERBY (MODULE <module-name>|ACLCAT <cat>|PATTERN <pattern>)]
```
which returns a set of all commands (unless filters), but excluding subcommands.
## Module API
A new module API, RM_CreateSubcommand, was added, in order to allow
module writer to define subcommands
## ACL changes:
1. Now, that each subcommand is actually a command, each has its own ACL id.
2. The old mechanism of allowed_subcommands is redundant
(blocking/allowing a subcommand is the same as blocking/allowing a regular command),
but we had to keep it, to support the widespread usage of allowed_subcommands
to block commands with certain args, that aren't subcommands (e.g. "-select +select|0").
3. I have renamed allowed_subcommands to allowed_firstargs to emphasize the difference.
4. Because subcommands are commands in ACL too, you can now use "-" to block subcommands
(e.g. "+client -client|kill"), which wasn't possible in the past.
5. It is also possible to use the allowed_firstargs mechanism with subcommand.
For example: `+config -config|set +config|set|loglevel` will block all CONFIG SET except
for setting the log level.
6. All of the ACL changes above required some amount of refactoring.
## Misc
1. There are two approaches: Either each subcommand has its own function or all
subcommands use the same function, determining what to do according to argv[0].
For now, I took the former approaches only with CONFIG and COMMAND,
while other commands use the latter approach (for smaller blamelog diff).
2. Deleted memoryGetKeys: It is no longer needed because MEMORY USAGE now uses the "range" key spec.
4. Bugfix: GETNAME was missing from CLIENT's help message.
5. Sentinel and Redis now use the same table, with the same function pointer.
Some commands have a different implementation in Sentinel, so we redirect
them (these are ROLE, PUBLISH, and INFO).
6. Command stats now show the stats per subcommand (e.g. instead of stats just
for "config" you will have stats for "config|set", "config|get", etc.)
7. It is now possible to use COMMAND directly on subcommands:
COMMAND INFO CONFIG|GET (The pipeline syntax was inspired from ACL, and
can be used in functions lookupCommandBySds and lookupCommandByCString)
8. STRALGO is now a container command (has "help")
## Breaking changes:
1. Command stats now show the stats per subcommand (see (5) above)
2021-10-20 04:52:57 -04:00
|
|
|
test {COMMAND GETKEYS GET} {
|
|
|
|
assert_equal {key} [r command getkeys get key]
|
|
|
|
}
|
|
|
|
|
2022-02-08 03:01:35 -05:00
|
|
|
test {COMMAND GETKEYSANDFLAGS} {
|
|
|
|
assert_equal {{k1 {OW update}}} [r command getkeysandflags set k1 v1]
|
|
|
|
assert_equal {{k1 {OW update}} {k2 {OW update}}} [r command getkeysandflags mset k1 v1 k2 v2]
|
|
|
|
assert_equal {{k1 {RW access delete}} {k2 {RW insert}}} [r command getkeysandflags LMOVE k1 k2 left right]
|
|
|
|
assert_equal {{k1 {RO access}} {k2 {OW update}}} [r command getkeysandflags sort k1 store k2]
|
|
|
|
}
|
|
|
|
|
Treat subcommands as commands (#9504)
## Intro
The purpose is to allow having different flags/ACL categories for
subcommands (Example: CONFIG GET is ok-loading but CONFIG SET isn't)
We create a small command table for every command that has subcommands
and each subcommand has its own flags, etc. (same as a "regular" command)
This commit also unites the Redis and the Sentinel command tables
## Affected commands
CONFIG
Used to have "admin ok-loading ok-stale no-script"
Changes:
1. Dropped "ok-loading" in all except GET (this doesn't change behavior since
there were checks in the code doing that)
XINFO
Used to have "read-only random"
Changes:
1. Dropped "random" in all except CONSUMERS
XGROUP
Used to have "write use-memory"
Changes:
1. Dropped "use-memory" in all except CREATE and CREATECONSUMER
COMMAND
No changes.
MEMORY
Used to have "random read-only"
Changes:
1. Dropped "random" in PURGE and USAGE
ACL
Used to have "admin no-script ok-loading ok-stale"
Changes:
1. Dropped "admin" in WHOAMI, GENPASS, and CAT
LATENCY
No changes.
MODULE
No changes.
SLOWLOG
Used to have "admin random ok-loading ok-stale"
Changes:
1. Dropped "random" in RESET
OBJECT
Used to have "read-only random"
Changes:
1. Dropped "random" in ENCODING and REFCOUNT
SCRIPT
Used to have "may-replicate no-script"
Changes:
1. Dropped "may-replicate" in all except FLUSH and LOAD
CLIENT
Used to have "admin no-script random ok-loading ok-stale"
Changes:
1. Dropped "random" in all except INFO and LIST
2. Dropped "admin" in ID, TRACKING, CACHING, GETREDIR, INFO, SETNAME, GETNAME, and REPLY
STRALGO
No changes.
PUBSUB
No changes.
CLUSTER
Changes:
1. Dropped "admin in countkeysinslots, getkeysinslot, info, nodes, keyslot, myid, and slots
SENTINEL
No changes.
(note that DEBUG also fits, but we decided not to convert it since it's for
debugging and anyway undocumented)
## New sub-command
This commit adds another element to the per-command output of COMMAND,
describing the list of subcommands, if any (in the same structure as "regular" commands)
Also, it adds a new subcommand:
```
COMMAND LIST [FILTERBY (MODULE <module-name>|ACLCAT <cat>|PATTERN <pattern>)]
```
which returns a set of all commands (unless filters), but excluding subcommands.
## Module API
A new module API, RM_CreateSubcommand, was added, in order to allow
module writer to define subcommands
## ACL changes:
1. Now, that each subcommand is actually a command, each has its own ACL id.
2. The old mechanism of allowed_subcommands is redundant
(blocking/allowing a subcommand is the same as blocking/allowing a regular command),
but we had to keep it, to support the widespread usage of allowed_subcommands
to block commands with certain args, that aren't subcommands (e.g. "-select +select|0").
3. I have renamed allowed_subcommands to allowed_firstargs to emphasize the difference.
4. Because subcommands are commands in ACL too, you can now use "-" to block subcommands
(e.g. "+client -client|kill"), which wasn't possible in the past.
5. It is also possible to use the allowed_firstargs mechanism with subcommand.
For example: `+config -config|set +config|set|loglevel` will block all CONFIG SET except
for setting the log level.
6. All of the ACL changes above required some amount of refactoring.
## Misc
1. There are two approaches: Either each subcommand has its own function or all
subcommands use the same function, determining what to do according to argv[0].
For now, I took the former approaches only with CONFIG and COMMAND,
while other commands use the latter approach (for smaller blamelog diff).
2. Deleted memoryGetKeys: It is no longer needed because MEMORY USAGE now uses the "range" key spec.
4. Bugfix: GETNAME was missing from CLIENT's help message.
5. Sentinel and Redis now use the same table, with the same function pointer.
Some commands have a different implementation in Sentinel, so we redirect
them (these are ROLE, PUBLISH, and INFO).
6. Command stats now show the stats per subcommand (e.g. instead of stats just
for "config" you will have stats for "config|set", "config|get", etc.)
7. It is now possible to use COMMAND directly on subcommands:
COMMAND INFO CONFIG|GET (The pipeline syntax was inspired from ACL, and
can be used in functions lookupCommandBySds and lookupCommandByCString)
8. STRALGO is now a container command (has "help")
## Breaking changes:
1. Command stats now show the stats per subcommand (see (5) above)
2021-10-20 04:52:57 -04:00
|
|
|
test {COMMAND GETKEYS MEMORY USAGE} {
|
|
|
|
assert_equal {key} [r command getkeys memory usage key]
|
|
|
|
}
|
|
|
|
|
|
|
|
test {COMMAND GETKEYS XGROUP} {
|
|
|
|
assert_equal {key} [r command getkeys xgroup create key groupname $]
|
|
|
|
}
|
|
|
|
|
2021-11-03 08:38:26 -04:00
|
|
|
test {COMMAND GETKEYS EVAL with keys} {
|
|
|
|
assert_equal {key} [r command getkeys eval "return 1" 1 key]
|
|
|
|
}
|
|
|
|
|
|
|
|
test {COMMAND GETKEYS EVAL without keys} {
|
|
|
|
assert_equal {} [r command getkeys eval "return 1" 0]
|
|
|
|
}
|
|
|
|
|
2021-11-28 02:02:38 -05:00
|
|
|
test {COMMAND GETKEYS LCS} {
|
|
|
|
assert_equal {key1 key2} [r command getkeys lcs key1 key2]
|
|
|
|
}
|
|
|
|
|
2023-07-03 05:45:18 -04:00
|
|
|
test {COMMAND GETKEYS MORE THAN 256 KEYS} {
|
|
|
|
set all_keys [list]
|
|
|
|
set numkeys 260
|
|
|
|
for {set i 1} {$i <= $numkeys} {incr i} {
|
|
|
|
lappend all_keys "key$i"
|
|
|
|
}
|
|
|
|
set all_keys_with_target [linsert $all_keys 0 target]
|
|
|
|
# we are using ZUNIONSTORE command since in order to reproduce allocation of a new buffer in getKeysPrepareResult
|
|
|
|
# when numkeys in result > 0
|
|
|
|
# we need a command that the final number of keys is not known in the first call to getKeysPrepareResult
|
|
|
|
# before the fix in that case data of old buffer was not copied to the new result buffer
|
|
|
|
# causing all previous keys (numkeys) data to be uninitialize
|
|
|
|
assert_equal $all_keys_with_target [r command getkeys ZUNIONSTORE target $numkeys {*}$all_keys]
|
|
|
|
}
|
|
|
|
|
2022-01-23 03:05:06 -05:00
|
|
|
test "COMMAND LIST syntax error" {
|
|
|
|
assert_error "ERR syntax error*" {r command list bad_arg}
|
|
|
|
assert_error "ERR syntax error*" {r command list filterby bad_arg}
|
|
|
|
assert_error "ERR syntax error*" {r command list filterby bad_arg bad_arg2}
|
Treat subcommands as commands (#9504)
## Intro
The purpose is to allow having different flags/ACL categories for
subcommands (Example: CONFIG GET is ok-loading but CONFIG SET isn't)
We create a small command table for every command that has subcommands
and each subcommand has its own flags, etc. (same as a "regular" command)
This commit also unites the Redis and the Sentinel command tables
## Affected commands
CONFIG
Used to have "admin ok-loading ok-stale no-script"
Changes:
1. Dropped "ok-loading" in all except GET (this doesn't change behavior since
there were checks in the code doing that)
XINFO
Used to have "read-only random"
Changes:
1. Dropped "random" in all except CONSUMERS
XGROUP
Used to have "write use-memory"
Changes:
1. Dropped "use-memory" in all except CREATE and CREATECONSUMER
COMMAND
No changes.
MEMORY
Used to have "random read-only"
Changes:
1. Dropped "random" in PURGE and USAGE
ACL
Used to have "admin no-script ok-loading ok-stale"
Changes:
1. Dropped "admin" in WHOAMI, GENPASS, and CAT
LATENCY
No changes.
MODULE
No changes.
SLOWLOG
Used to have "admin random ok-loading ok-stale"
Changes:
1. Dropped "random" in RESET
OBJECT
Used to have "read-only random"
Changes:
1. Dropped "random" in ENCODING and REFCOUNT
SCRIPT
Used to have "may-replicate no-script"
Changes:
1. Dropped "may-replicate" in all except FLUSH and LOAD
CLIENT
Used to have "admin no-script random ok-loading ok-stale"
Changes:
1. Dropped "random" in all except INFO and LIST
2. Dropped "admin" in ID, TRACKING, CACHING, GETREDIR, INFO, SETNAME, GETNAME, and REPLY
STRALGO
No changes.
PUBSUB
No changes.
CLUSTER
Changes:
1. Dropped "admin in countkeysinslots, getkeysinslot, info, nodes, keyslot, myid, and slots
SENTINEL
No changes.
(note that DEBUG also fits, but we decided not to convert it since it's for
debugging and anyway undocumented)
## New sub-command
This commit adds another element to the per-command output of COMMAND,
describing the list of subcommands, if any (in the same structure as "regular" commands)
Also, it adds a new subcommand:
```
COMMAND LIST [FILTERBY (MODULE <module-name>|ACLCAT <cat>|PATTERN <pattern>)]
```
which returns a set of all commands (unless filters), but excluding subcommands.
## Module API
A new module API, RM_CreateSubcommand, was added, in order to allow
module writer to define subcommands
## ACL changes:
1. Now, that each subcommand is actually a command, each has its own ACL id.
2. The old mechanism of allowed_subcommands is redundant
(blocking/allowing a subcommand is the same as blocking/allowing a regular command),
but we had to keep it, to support the widespread usage of allowed_subcommands
to block commands with certain args, that aren't subcommands (e.g. "-select +select|0").
3. I have renamed allowed_subcommands to allowed_firstargs to emphasize the difference.
4. Because subcommands are commands in ACL too, you can now use "-" to block subcommands
(e.g. "+client -client|kill"), which wasn't possible in the past.
5. It is also possible to use the allowed_firstargs mechanism with subcommand.
For example: `+config -config|set +config|set|loglevel` will block all CONFIG SET except
for setting the log level.
6. All of the ACL changes above required some amount of refactoring.
## Misc
1. There are two approaches: Either each subcommand has its own function or all
subcommands use the same function, determining what to do according to argv[0].
For now, I took the former approaches only with CONFIG and COMMAND,
while other commands use the latter approach (for smaller blamelog diff).
2. Deleted memoryGetKeys: It is no longer needed because MEMORY USAGE now uses the "range" key spec.
4. Bugfix: GETNAME was missing from CLIENT's help message.
5. Sentinel and Redis now use the same table, with the same function pointer.
Some commands have a different implementation in Sentinel, so we redirect
them (these are ROLE, PUBLISH, and INFO).
6. Command stats now show the stats per subcommand (e.g. instead of stats just
for "config" you will have stats for "config|set", "config|get", etc.)
7. It is now possible to use COMMAND directly on subcommands:
COMMAND INFO CONFIG|GET (The pipeline syntax was inspired from ACL, and
can be used in functions lookupCommandBySds and lookupCommandByCString)
8. STRALGO is now a container command (has "help")
## Breaking changes:
1. Command stats now show the stats per subcommand (see (5) above)
2021-10-20 04:52:57 -04:00
|
|
|
}
|
|
|
|
|
2022-01-23 03:05:06 -05:00
|
|
|
test "COMMAND LIST WITHOUT FILTERBY" {
|
|
|
|
set commands [r command list]
|
|
|
|
assert_not_equal [lsearch $commands "set"] -1
|
|
|
|
assert_not_equal [lsearch $commands "client|list"] -1
|
|
|
|
}
|
|
|
|
|
|
|
|
test "COMMAND LIST FILTERBY ACLCAT against non existing category" {
|
|
|
|
assert_equal {} [r command list filterby aclcat non_existing_category]
|
|
|
|
}
|
|
|
|
|
|
|
|
test "COMMAND LIST FILTERBY ACLCAT - list all commands/subcommands" {
|
|
|
|
set commands [r command list filterby aclcat scripting]
|
|
|
|
assert_not_equal [lsearch $commands "eval"] -1
|
|
|
|
assert_not_equal [lsearch $commands "script|kill"] -1
|
|
|
|
|
|
|
|
# Negative check, a command that should not be here
|
|
|
|
assert_equal [lsearch $commands "set"] -1
|
|
|
|
}
|
|
|
|
|
|
|
|
test "COMMAND LIST FILTERBY PATTERN - list all commands/subcommands" {
|
|
|
|
# Exact command match.
|
|
|
|
assert_equal {set} [r command list filterby pattern set]
|
|
|
|
assert_equal {get} [r command list filterby pattern get]
|
|
|
|
|
|
|
|
# Return the parent command and all the subcommands below it.
|
|
|
|
set commands [r command list filterby pattern config*]
|
|
|
|
assert_not_equal [lsearch $commands "config"] -1
|
|
|
|
assert_not_equal [lsearch $commands "config|get"] -1
|
|
|
|
|
|
|
|
# We can filter subcommands under a parent command.
|
|
|
|
set commands [r command list filterby pattern config|*re*]
|
|
|
|
assert_not_equal [lsearch $commands "config|resetstat"] -1
|
|
|
|
assert_not_equal [lsearch $commands "config|rewrite"] -1
|
|
|
|
|
|
|
|
# We can filter subcommands across parent commands.
|
|
|
|
set commands [r command list filterby pattern cl*help]
|
|
|
|
assert_not_equal [lsearch $commands "client|help"] -1
|
|
|
|
assert_not_equal [lsearch $commands "cluster|help"] -1
|
|
|
|
|
|
|
|
# Negative check, command that doesn't exist.
|
|
|
|
assert_equal {} [r command list filterby pattern non_exists]
|
|
|
|
assert_equal {} [r command list filterby pattern non_exists*]
|
|
|
|
}
|
|
|
|
|
|
|
|
test "COMMAND LIST FILTERBY MODULE against non existing module" {
|
|
|
|
# This should be empty, the real one is in subcommands.tcl
|
|
|
|
assert_equal {} [r command list filterby module non_existing_module]
|
Treat subcommands as commands (#9504)
## Intro
The purpose is to allow having different flags/ACL categories for
subcommands (Example: CONFIG GET is ok-loading but CONFIG SET isn't)
We create a small command table for every command that has subcommands
and each subcommand has its own flags, etc. (same as a "regular" command)
This commit also unites the Redis and the Sentinel command tables
## Affected commands
CONFIG
Used to have "admin ok-loading ok-stale no-script"
Changes:
1. Dropped "ok-loading" in all except GET (this doesn't change behavior since
there were checks in the code doing that)
XINFO
Used to have "read-only random"
Changes:
1. Dropped "random" in all except CONSUMERS
XGROUP
Used to have "write use-memory"
Changes:
1. Dropped "use-memory" in all except CREATE and CREATECONSUMER
COMMAND
No changes.
MEMORY
Used to have "random read-only"
Changes:
1. Dropped "random" in PURGE and USAGE
ACL
Used to have "admin no-script ok-loading ok-stale"
Changes:
1. Dropped "admin" in WHOAMI, GENPASS, and CAT
LATENCY
No changes.
MODULE
No changes.
SLOWLOG
Used to have "admin random ok-loading ok-stale"
Changes:
1. Dropped "random" in RESET
OBJECT
Used to have "read-only random"
Changes:
1. Dropped "random" in ENCODING and REFCOUNT
SCRIPT
Used to have "may-replicate no-script"
Changes:
1. Dropped "may-replicate" in all except FLUSH and LOAD
CLIENT
Used to have "admin no-script random ok-loading ok-stale"
Changes:
1. Dropped "random" in all except INFO and LIST
2. Dropped "admin" in ID, TRACKING, CACHING, GETREDIR, INFO, SETNAME, GETNAME, and REPLY
STRALGO
No changes.
PUBSUB
No changes.
CLUSTER
Changes:
1. Dropped "admin in countkeysinslots, getkeysinslot, info, nodes, keyslot, myid, and slots
SENTINEL
No changes.
(note that DEBUG also fits, but we decided not to convert it since it's for
debugging and anyway undocumented)
## New sub-command
This commit adds another element to the per-command output of COMMAND,
describing the list of subcommands, if any (in the same structure as "regular" commands)
Also, it adds a new subcommand:
```
COMMAND LIST [FILTERBY (MODULE <module-name>|ACLCAT <cat>|PATTERN <pattern>)]
```
which returns a set of all commands (unless filters), but excluding subcommands.
## Module API
A new module API, RM_CreateSubcommand, was added, in order to allow
module writer to define subcommands
## ACL changes:
1. Now, that each subcommand is actually a command, each has its own ACL id.
2. The old mechanism of allowed_subcommands is redundant
(blocking/allowing a subcommand is the same as blocking/allowing a regular command),
but we had to keep it, to support the widespread usage of allowed_subcommands
to block commands with certain args, that aren't subcommands (e.g. "-select +select|0").
3. I have renamed allowed_subcommands to allowed_firstargs to emphasize the difference.
4. Because subcommands are commands in ACL too, you can now use "-" to block subcommands
(e.g. "+client -client|kill"), which wasn't possible in the past.
5. It is also possible to use the allowed_firstargs mechanism with subcommand.
For example: `+config -config|set +config|set|loglevel` will block all CONFIG SET except
for setting the log level.
6. All of the ACL changes above required some amount of refactoring.
## Misc
1. There are two approaches: Either each subcommand has its own function or all
subcommands use the same function, determining what to do according to argv[0].
For now, I took the former approaches only with CONFIG and COMMAND,
while other commands use the latter approach (for smaller blamelog diff).
2. Deleted memoryGetKeys: It is no longer needed because MEMORY USAGE now uses the "range" key spec.
4. Bugfix: GETNAME was missing from CLIENT's help message.
5. Sentinel and Redis now use the same table, with the same function pointer.
Some commands have a different implementation in Sentinel, so we redirect
them (these are ROLE, PUBLISH, and INFO).
6. Command stats now show the stats per subcommand (e.g. instead of stats just
for "config" you will have stats for "config|set", "config|get", etc.)
7. It is now possible to use COMMAND directly on subcommands:
COMMAND INFO CONFIG|GET (The pipeline syntax was inspired from ACL, and
can be used in functions lookupCommandBySds and lookupCommandByCString)
8. STRALGO is now a container command (has "help")
## Breaking changes:
1. Command stats now show the stats per subcommand (see (5) above)
2021-10-20 04:52:57 -04:00
|
|
|
}
|
2022-01-22 07:09:40 -05:00
|
|
|
|
|
|
|
test {COMMAND INFO of invalid subcommands} {
|
|
|
|
assert_equal {{}} [r command info get|key]
|
|
|
|
assert_equal {{}} [r command info config|get|key]
|
|
|
|
}
|
Fixed SET and BITFIELD commands being wrongly marked movablekeys (#10837)
The SET and BITFIELD command were added `get_keys_function` in #10148, causing
them to be wrongly marked movablekeys in `populateCommandMovableKeys`.
This was an unintended side effect introduced in #10148 (7.0 RC1)
which could cause some clients an extra round trip for these commands in cluster mode.
Since we define movablekeys as a way to determine if the legacy range [first, last, step]
doesn't find all keys, then we need a completely different approach.
The right approach should be to check if the legacy range covers all key-specs,
and if none of the key-specs have the INCOMPLETE flag.
This way, we don't need to look at getkeys_proc of VARIABLE_FLAG at all.
Probably with the exception of modules, who may still not be using key-specs.
In this PR, we removed `populateCommandMovableKeys` and put its logic in
`populateCommandLegacyRangeSpec`.
In order to properly serve both old and new modules, we must probably keep relying
CMD_MODULE_GETKEYS, but do that only for modules that don't declare key-specs.
For ones that do, we need to take the same approach we take with native redis commands.
This approach was proposed by Oran. Fixes #10833
Co-authored-by: Oran Agra <oran@redislabs.com>
2022-06-12 01:22:18 -04:00
|
|
|
|
|
|
|
foreach cmd {SET GET MSET BITFIELD LMOVE LPOP BLPOP PING MEMORY MEMORY|USAGE RENAME GEORADIUS_RO} {
|
|
|
|
test "$cmd command will not be marked with movablekeys" {
|
|
|
|
set info [lindex [r command info $cmd] 0]
|
|
|
|
assert_no_match {*movablekeys*} [lindex $info 2]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach cmd {ZUNIONSTORE XREAD EVAL SORT SORT_RO MIGRATE GEORADIUS} {
|
|
|
|
test "$cmd command is marked with movablekeys" {
|
|
|
|
set info [lindex [r command info $cmd] 0]
|
|
|
|
assert_match {*movablekeys*} [lindex $info 2]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 11:15:18 -04:00
|
|
|
}
|