Unverified Commit 23325c13 authored by Binbin's avatar Binbin Committed by GitHub
Browse files

sub-command support for ACL CAT and COMMAND LIST. redisCommand always stores fullname (#10127)



Summary of changes:
1. Rename `redisCommand->name` to `redisCommand->declared_name`, it is a
  const char * for native commands and SDS for module commands.
2. Store the [sub]command fullname in `redisCommand->fullname` (sds).
3. List subcommands in `ACL CAT`
4. List subcommands in `COMMAND LIST`
5. `moduleUnregisterCommands` now will also free the module subcommands.
6. RM_GetCurrentCommandName returns full command name

Other changes:
1. Add `addReplyErrorArity` and `addReplyErrorExpireTime`
2. Remove `getFullCommandName` function that now is useless.
3. Some cleanups about `fullname` since now it is SDS.
4. Delete `populateSingleCommand` function from server.h that is useless.
5. Added tests to cover this change.
6. Add some module unload tests and fix the leaks
7. Make error messages uniform, make sure they always contain the full command
  name and that it's quoted.
7. Fixes some typos

see the history in #9504, fixes #10124
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
Co-authored-by: default avatarguybe7 <guy.benoish@redislabs.com>
parent a6fd2a46
set testmodule [file normalize tests/modules/misc.so]
start_server {tags {"modules"}} {
r module load $testmodule
......@@ -133,4 +132,8 @@ start_server {tags {"modules"}} {
set x [r test.monotonic_time]
assert { [r test.monotonic_time] >= $x }
}
test "Unload the module - misc" {
assert_equal {OK} [r module unload misc]
}
}
......@@ -574,6 +574,11 @@ tags "modules" {
assert_equal [$replica ttl k1] -1
}
test "Unload the module - propagate-test/testkeyspace" {
assert_equal {OK} [r module unload propagate-test]
assert_equal {OK} [r module unload testkeyspace]
}
assert_equal [s -1 unexpected_error_replies] 0
}
}
......@@ -598,6 +603,7 @@ tags "modules aof" {
# Load the AOF
r debug loadaof
assert_equal {OK} [r module unload propagate-test]
assert_equal [s 0 unexpected_error_replies] 0
}
}
......
......@@ -94,4 +94,8 @@ start_server {tags {"modules"}} {
assert_match "An error" $e
}
}
test "Unload the module - replywith" {
assert_equal {OK} [r module unload replywith]
}
}
......@@ -49,4 +49,8 @@ start_server {tags {"modules"}} {
r sadd ss 3
lsort [r scan.scan_key ss]
} {{1 {}} {2 {}} {3 {}}}
test "Unload the module - scan" {
assert_equal {OK} [r module unload scan]
}
}
......@@ -152,4 +152,8 @@ start_server {tags {"modules"}} {
assert_equal 100 [r stream.trim mystream minid ~ +]
assert_equal 0 [r xlen mystream]
}
test "Unload the module - stream" {
assert_equal {OK} [r module unload stream]
}
}
......@@ -21,9 +21,33 @@ start_server {tags {"modules"}} {
test "Module pure-container command fails on arity error" {
catch {r subcommands.bitarray} e
assert_match {*wrong number of arguments*} $e
assert_match {*wrong number of arguments for 'subcommands.bitarray' command} $e
# Subcommands can be called
assert_equal [r subcommands.bitarray get k1] {OK}
}
test "Module get current command fullname" {
assert_equal [r subcommands.parent_get_fullname] {subcommands.parent_get_fullname}
}
test "Module get current subcommand fullname" {
assert_equal [r subcommands.sub get_fullname] {subcommands.sub|get_fullname}
}
test "COMMAND LIST FILTERBY MODULE" {
assert_equal {} [r command list filterby module non_existing]
set commands [r command list filterby module subcommands]
assert_not_equal [lsearch $commands "subcommands.bitarray"] -1
assert_not_equal [lsearch $commands "subcommands.bitarray|set"] -1
assert_not_equal [lsearch $commands "subcommands.parent_get_fullname"] -1
assert_not_equal [lsearch $commands "subcommands.sub|get_fullname"] -1
assert_equal [lsearch $commands "set"] -1
}
test "Unload the module - subcommands" {
assert_equal {OK} [r module unload subcommands]
}
}
......@@ -53,5 +53,9 @@ start_server {tags {"modules"}} {
# verify id does not exist
assert_equal {} [r test.gettimer $id]
}
test "Unload the module - timer" {
assert_equal {OK} [r module unload timer]
}
}
......@@ -13,4 +13,8 @@ start_server {tags {"modules"}} {
assert_equal 1 [r zset.rem k world]
assert_equal 0 [r exists k]
}
test "Unload the module - zset" {
assert_equal {OK} [r module unload zset]
}
}
......@@ -104,7 +104,7 @@ start_server {tags {"pause network"}} {
test "Test clients with syntax errors will get responses immediately" {
r client PAUSE 100000 WRITE
catch {r set FOO} err
assert_match "ERR wrong number of arguments for *" $err
assert_match "ERR wrong number of arguments for 'set' command" $err
r client unpause
}
......
......@@ -310,10 +310,10 @@ start_server {tags {"hash"}} {
set _ $result
} {foo}
test {HMSET wrong number of args} {
catch {r hmset smallhash key1 val1 key2} err
format $err
} {*wrong number*}
test {HSET/HMSET wrong number of args} {
assert_error {*wrong number of arguments for 'hset' command} {r hset smallhash key1 val1 key2}
assert_error {*wrong number of arguments for 'hmset' command} {r hmset smallhash key1 val1 key2}
}
test {HMSET - small hash} {
set args {}
......
......@@ -486,6 +486,11 @@ start_server {
assert_equal c [r lpop mylist2]
}
test "LPOP/RPOP with wrong number of arguments" {
assert_error {*wrong number of arguments for 'lpop' command} {r lpop key 1 1}
assert_error {*wrong number of arguments for 'rpop' command} {r rpop key 2 2}
}
test {RPOP/LPOP with the optional count argument} {
assert_equal 7 [r lpush listcount aa bb cc dd ee ff gg]
assert_equal {gg} [r lpop listcount 1]
......@@ -1600,9 +1605,9 @@ foreach {pop} {BLPOP BLMPOP_LEFT} {
}
test {LMPOP with illegal argument} {
assert_error "ERR wrong number of arguments*" {r lmpop}
assert_error "ERR wrong number of arguments*" {r lmpop 1}
assert_error "ERR wrong number of arguments*" {r lmpop 1 mylist{t}}
assert_error "ERR wrong number of arguments for 'lmpop' command" {r lmpop}
assert_error "ERR wrong number of arguments for 'lmpop' command" {r lmpop 1}
assert_error "ERR wrong number of arguments for 'lmpop' command" {r lmpop 1 mylist{t}}
assert_error "ERR numkeys*" {r lmpop 0 mylist{t} LEFT}
assert_error "ERR numkeys*" {r lmpop a mylist{t} LEFT}
......
......@@ -144,8 +144,8 @@ start_server {
} {3}
test "SINTERCARD with illegal arguments" {
assert_error "ERR wrong number of arguments*" {r sintercard}
assert_error "ERR wrong number of arguments*" {r sintercard 1}
assert_error "ERR wrong number of arguments for 'sintercard' command" {r sintercard}
assert_error "ERR wrong number of arguments for 'sintercard' command" {r sintercard 1}
assert_error "ERR numkeys*" {r sintercard 0 myset{t}}
assert_error "ERR numkeys*" {r sintercard a myset{t}}
......
......@@ -52,6 +52,12 @@ set content {} ;# Will be populated with Tcl side copy of the stream content.
start_server {
tags {"stream"}
} {
test "XADD wrong number of args" {
assert_error {*wrong number of arguments for 'xadd' command} {r XADD mystream}
assert_error {*wrong number of arguments for 'xadd' command} {r XADD mystream *}
assert_error {*wrong number of arguments for 'xadd' command} {r XADD mystream * field}
}
test {XADD can add entries into a stream that XRANGE can fetch} {
r XADD mystream * item 1 value a
r XADD mystream * item 2 value b
......@@ -797,11 +803,11 @@ start_server {tags {"stream needs:debug"} overrides {appendonly yes aof-use-rdb-
start_server {tags {"stream"}} {
test {XGROUP HELP should not have unexpected options} {
catch {r XGROUP help xxx} e
assert_match "*wrong number of arguments*" $e
assert_match "*wrong number of arguments for 'xgroup|help' command" $e
}
test {XINFO HELP should not have unexpected options} {
catch {r XINFO help xxx} e
assert_match "*wrong number of arguments*" $e
assert_match "*wrong number of arguments for 'xinfo|help' command" $e
}
}
......@@ -155,7 +155,7 @@ start_server {tags {"string"}} {
set ex {}
catch {r getex} ex
set ex
} {*wrong number of arguments*}
} {*wrong number of arguments for 'getex' command}
test "GETDEL command" {
r del foo
......@@ -221,10 +221,10 @@ start_server {tags {"string"}} {
r mget x{t} y{t} z{t}
} [list 10 {foo bar} "x x x x x x x\n\n\r\n"]
test {MSET wrong number of args} {
catch {r mset x{t} 10 y{t} "foo bar" z{t}} err
format $err
} {*wrong number*}
test {MSET/MSETNX wrong number of args} {
assert_error {*wrong number of arguments for 'mset' command} {r mset x{t} 10 y{t} "foo bar" z{t}}
assert_error {*wrong number of arguments for 'msetnx' command} {r msetnx x{t} 20 y{t} "foo bar" z{t}}
}
test {MSETNX with already existent key} {
list [r msetnx x1{t} xxx y2{t} yyy x{t} 20] [r exists x1{t}] [r exists y2{t}]
......
......@@ -1157,9 +1157,9 @@ start_server {tags {"zset"}} {
}
test "ZMPOP with illegal argument" {
assert_error "ERR wrong number of arguments*" {r zmpop}
assert_error "ERR wrong number of arguments*" {r zmpop 1}
assert_error "ERR wrong number of arguments*" {r zmpop 1 myzset{t}}
assert_error "ERR wrong number of arguments for 'zmpop' command" {r zmpop}
assert_error "ERR wrong number of arguments for 'zmpop' command" {r zmpop 1}
assert_error "ERR wrong number of arguments for 'zmpop' command" {r zmpop 1 myzset{t}}
assert_error "ERR numkeys*" {r zmpop 0 myzset{t} MIN}
assert_error "ERR numkeys*" {r zmpop a myzset{t} MIN}
......@@ -1475,6 +1475,16 @@ start_server {tags {"zset"}} {
assert_error "*not*float*" {r zadd myzset "" abc}
}
test "zunionInterDiffGenericCommand at least 1 input key" {
assert_error {*at least 1 input key * 'zunion' command} {r zunion 0 key{t}}
assert_error {*at least 1 input key * 'zunionstore' command} {r zunionstore dst_key{t} 0 key{t}}
assert_error {*at least 1 input key * 'zinter' command} {r zinter 0 key{t}}
assert_error {*at least 1 input key * 'zinterstore' command} {r zinterstore dst_key{t} 0 key{t}}
assert_error {*at least 1 input key * 'zdiff' command} {r zdiff 0 key{t}}
assert_error {*at least 1 input key * 'zdiffstore' command} {r zdiffstore dst_key{t} 0 key{t}}
assert_error {*at least 1 input key * 'zintercard' command} {r zintercard 0 key{t}}
}
proc stressers {encoding} {
set original_max_entries [lindex [r config get zset-max-ziplist-entries] 1]
set original_max_value [lindex [r config get zset-max-ziplist-value] 1]
......@@ -1950,9 +1960,9 @@ start_server {tags {"zset"}} {
}
test "BZMPOP with illegal argument" {
assert_error "ERR wrong number of arguments*" {r bzmpop}
assert_error "ERR wrong number of arguments*" {r bzmpop 0 1}
assert_error "ERR wrong number of arguments*" {r bzmpop 0 1 myzset{t}}
assert_error "ERR wrong number of arguments for 'bzmpop' command" {r bzmpop}
assert_error "ERR wrong number of arguments for 'bzmpop' command" {r bzmpop 0 1}
assert_error "ERR wrong number of arguments for 'bzmpop' command" {r bzmpop 0 1 myzset{t}}
assert_error "ERR numkeys*" {r bzmpop 1 0 myzset{t} MIN}
assert_error "ERR numkeys*" {r bzmpop 1 a myzset{t} MIN}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment