mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
867816003e
Delete the hardcoded command table and replace it with an auto-generated table, based on a JSON file that describes the commands (each command must have a JSON file). These JSON files are the SSOT of everything there is to know about Redis commands, and it is reflected fully in COMMAND INFO. These JSON files are used to generate commands.c (using a python script), which is then committed to the repo and compiled. The purpose is: * Clients and proxies will be able to get much more info from redis, instead of relying on hard coded logic. * drop the dependency between Redis-user and the commands.json in redis-doc. * delete help.h and have redis-cli learn everything it needs to know just by issuing COMMAND (will be done in a separate PR) * redis.io should stop using commands.json and learn everything from Redis (ultimately one of the release artifacts should be a large JSON, containing all the information about all of the commands, which will be generated from COMMAND's reply) * the byproduct of this is: * module commands will be able to provide that info and possibly be more of a first-class citizens * in theory, one may be able to generate a redis client library for a strictly typed language, by using this info. ### Interface changes #### COMMAND INFO's reply change (and arg-less COMMAND) Before this commit the reply at index 7 contained the key-specs list and reply at index 8 contained the sub-commands list (Both unreleased). Now, reply at index 7 is a map of: - summary - short command description - since - debut version - group - command group - complexity - complexity string - doc-flags - flags used for documentation (e.g. "deprecated") - deprecated-since - if deprecated, from which version? - replaced-by - if deprecated, which command replaced it? - history - a list of (version, what-changed) tuples - hints - a list of strings, meant to provide hints for clients/proxies. see https://github.com/redis/redis/issues/9876 - arguments - an array of arguments. each element is a map, with the possibility of nesting (sub-arguments) - key-specs - an array of keys specs (already in unstable, just changed location) - subcommands - a list of sub-commands (already in unstable, just changed location) - reply-schema - will be added in the future (see https://github.com/redis/redis/issues/9845) more details on these can be found in https://github.com/redis/redis-doc/pull/1697 only the first three fields are mandatory #### API changes (unreleased API obviously) now they take RedisModuleCommand opaque pointer instead of looking up the command by name - RM_CreateSubcommand - RM_AddCommandKeySpec - RM_SetCommandKeySpecBeginSearchIndex - RM_SetCommandKeySpecBeginSearchKeyword - RM_SetCommandKeySpecFindKeysRange - RM_SetCommandKeySpecFindKeysKeynum Currently, we did not add module API to provide additional information about their commands because we couldn't agree on how the API should look like, see https://github.com/redis/redis/issues/9944. ### Somehow related changes 1. Literals should be in uppercase while placeholder in lowercase. Now all the GEO* command will be documented with M|KM|FT|MI and can take both lowercase and uppercase ### Unrelated changes 1. Bugfix: no_madaory_keys was absent in COMMAND's reply 2. expose CMD_MODULE as "module" via COMMAND 3. have a dedicated uint64 for ACL categories (instead of having them in the same uint64 as command flags) Co-authored-by: Itamar Haber <itamar@garantiadata.com>
67 lines
3.6 KiB
Tcl
67 lines
3.6 KiB
Tcl
set testmodule [file normalize tests/modules/keyspecs.so]
|
|
|
|
start_server {tags {"modules"}} {
|
|
r module load $testmodule
|
|
|
|
test "Module key specs: Legacy" {
|
|
set reply [r command info kspec.legacy]
|
|
# Verify (first, last, step)
|
|
assert_equal [lindex [lindex $reply 0] 3] 1
|
|
assert_equal [lindex [lindex $reply 0] 4] 2
|
|
assert_equal [lindex [lindex $reply 0] 5] 1
|
|
# create a dict for easy lookup
|
|
unset -nocomplain mydict
|
|
foreach {k v} [lindex [lindex $reply 0] 7] {
|
|
dict append mydict $k $v
|
|
}
|
|
# Verify key-specs
|
|
set keyspecs [dict get $mydict key-specs]
|
|
assert_equal [lindex $keyspecs 0] {flags read begin-search {type index spec {index 1}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
|
|
assert_equal [lindex $keyspecs 1] {flags write begin-search {type index spec {index 2}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
|
|
}
|
|
|
|
test "Module key specs: Complex specs, case 1" {
|
|
set reply [r command info kspec.complex1]
|
|
# Verify (first, last, step)
|
|
assert_equal [lindex [lindex $reply 0] 3] 1
|
|
assert_equal [lindex [lindex $reply 0] 4] 1
|
|
assert_equal [lindex [lindex $reply 0] 5] 1
|
|
# create a dict for easy lookup
|
|
unset -nocomplain mydict
|
|
foreach {k v} [lindex [lindex $reply 0] 7] {
|
|
dict append mydict $k $v
|
|
}
|
|
# Verify key-specs
|
|
set keyspecs [dict get $mydict key-specs]
|
|
assert_equal [lindex $keyspecs 0] {flags {} begin-search {type index spec {index 1}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
|
|
assert_equal [lindex $keyspecs 1] {flags write begin-search {type keyword spec {keyword STORE startfrom 2}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
|
|
assert_equal [lindex $keyspecs 2] {flags read begin-search {type keyword spec {keyword KEYS startfrom 2}} find-keys {type keynum spec {keynumidx 0 firstkey 1 keystep 1}}}
|
|
}
|
|
|
|
test "Module key specs: Complex specs, case 2" {
|
|
set reply [r command info kspec.complex2]
|
|
# Verify (first, last, step)
|
|
assert_equal [lindex [lindex $reply 0] 3] 1
|
|
assert_equal [lindex [lindex $reply 0] 4] 2
|
|
assert_equal [lindex [lindex $reply 0] 5] 1
|
|
# create a dict for easy lookup
|
|
unset -nocomplain mydict
|
|
foreach {k v} [lindex [lindex $reply 0] 7] {
|
|
dict append mydict $k $v
|
|
}
|
|
# Verify key-specs
|
|
set keyspecs [dict get $mydict key-specs]
|
|
assert_equal [lindex $keyspecs 0] {flags write begin-search {type keyword spec {keyword STORE startfrom 5}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
|
|
assert_equal [lindex $keyspecs 1] {flags read begin-search {type index spec {index 1}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
|
|
assert_equal [lindex $keyspecs 2] {flags read begin-search {type index spec {index 2}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
|
|
assert_equal [lindex $keyspecs 3] {flags write begin-search {type index spec {index 3}} find-keys {type keynum spec {keynumidx 0 firstkey 1 keystep 1}}}
|
|
assert_equal [lindex $keyspecs 4] {flags write begin-search {type keyword spec {keyword MOREKEYS startfrom 5}} find-keys {type range spec {lastkey -1 keystep 1 limit 0}}}
|
|
}
|
|
|
|
test "Module command list filtering" {
|
|
;# Note: we piggyback this tcl file to test the general functionality of command list filtering
|
|
set reply [r command list filterby module keyspecs]
|
|
assert_equal [lsort $reply] {kspec.complex1 kspec.complex2 kspec.legacy}
|
|
}
|
|
}
|