mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
3204a03574
Syntax: `COMMAND DOCS [<command name> ...]` Background: Apparently old version of hiredis (and thus also redis-cli) can't support more than 7 levels of multi-bulk nesting. The solution is to move all the doc related metadata from COMMAND to a new COMMAND DOCS sub-command. The new DOCS sub-command returns a map of commands (not an array like in COMMAND), And the same goes for the `subcommands` field inside it (also contains a map) Besides that, the remaining new fields of COMMAND (hints, key-specs, and sub-commands), are placed in the outer array rather than a nested map. this was done mainly for consistency with the old format. Other changes: --- * Allow COMMAND INFO with no arguments, which returns all commands, so that we can some day deprecated the plain COMMAND (no args) * Reduce the amount of deferred replies from both COMMAND and COMMAND DOCS, especially in the inner loops, since these create many small reply objects, which lead to many small write syscalls and many small TCP packets. To make this easier, when populating the command table, we count the history, args, and hints so we later know their size in advance. Additionally, the movablekeys flag was moved into the flags register. * Update generate-commands-json.py to take the data from both command, it now executes redis-cli directly, instead of taking input from stdin. * Sub-commands in both COMMAND (and COMMAND INFO), and also COMMAND DOCS, show their full name. i.e. CONFIG * GET will be shown as `config|get` rather than just `get`. This will be visible both when asking for `COMMAND INFO config` and COMMAND INFO config|get`, but is especially important for the later. i.e. imagine someone doing `COMMAND INFO slowlog|get config|get` not being able to distinguish between the two items in the array response.
30 lines
1.6 KiB
Tcl
30 lines
1.6 KiB
Tcl
set testmodule [file normalize tests/modules/subcommands.so]
|
|
|
|
start_server {tags {"modules"}} {
|
|
r module load $testmodule
|
|
|
|
test "Module subcommands via COMMAND" {
|
|
# Verify that module subcommands are displayed correctly in COMMAND
|
|
set command_reply [r command info subcommands.bitarray]
|
|
set first_cmd [lindex $command_reply 0]
|
|
set subcmds_in_command [lsort [lindex $first_cmd 9]]
|
|
assert_equal [lindex $subcmds_in_command 0] {subcommands.bitarray|get -2 module 1 1 1 {} {} {{flags read begin_search {type index spec {index 1}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}} {}}
|
|
assert_equal [lindex $subcmds_in_command 1] {subcommands.bitarray|set -2 module 1 1 1 {} {} {{flags write begin_search {type index spec {index 1}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}} {}}
|
|
|
|
# Verify that module subcommands are displayed correctly in COMMAND DOCS
|
|
set docs_reply [r command docs subcommands.bitarray]
|
|
set docs [dict create {*}[lindex $docs_reply 1]]
|
|
set subcmds_in_cmd_docs [dict create {*}[dict get $docs subcommands]]
|
|
assert_equal [dict get $subcmds_in_cmd_docs "subcommands.bitarray|get"] {summary {} since {} group module}
|
|
assert_equal [dict get $subcmds_in_cmd_docs "subcommands.bitarray|set"] {summary {} since {} group module}
|
|
}
|
|
|
|
test "Module pure-container command fails on arity error" {
|
|
catch {r subcommands.bitarray} e
|
|
assert_match {*wrong number of arguments*} $e
|
|
|
|
# Subcommands can be called
|
|
assert_equal [r subcommands.bitarray get k1] {OK}
|
|
}
|
|
}
|