Unverified Commit 86781600 authored by guybe7's avatar guybe7 Committed by GitHub
Browse files

Auto-generate the command table from JSON files (#9656)

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: default avatarItamar Haber <itamar@garantiadata.com>
parent fbfdf513
{
"INFO": {
"summary": "Get array of specific Redis command details",
"complexity": "O(N) when N is number of commands to look up",
"group": "server",
"since": "2.8.13",
"arity": -3,
"container": "COMMAND",
"function": "commandInfoCommand",
"command_flags": [
"LOADING",
"STALE"
],
"acl_categories": [
"CONNECTION"
],
"arguments": [
{
"name": "command-name",
"type": "string",
"multiple": true
}
]
}
}
{
"LIST": {
"summary": "Get an array of Redis command names",
"complexity": "O(N) where N is the total number of Redis commands",
"group": "server",
"since": "7.0.0",
"arity": -2,
"container": "COMMAND",
"function": "commandListCommand",
"command_flags": [
"LOADING",
"STALE"
],
"acl_categories": [
"CONNECTION"
],
"arguments": [
{
"name": "filterby",
"token": "FILTERBY",
"type": "oneof",
"optional": true,
"arguments": [
{
"name": "module-name",
"type": "string",
"token": "MODULE"
},
{
"name": "category",
"type": "string",
"token": "ACLCAT"
},
{
"name": "pattern",
"type": "pattern",
"token": "PATTERN"
}
]
}
]
}
}
{
"COMMAND": {
"summary": "Get array of Redis command details",
"complexity": "O(N) where N is the total number of Redis commands",
"group": "server",
"since": "2.8.13",
"arity": -1,
"function": "commandCommand",
"command_flags": [
"RANDOM",
"LOADING",
"STALE",
"SENTINEL"
],
"acl_categories": [
"CONNECTION"
]
}
}
{
"GET": {
"summary": "Get the values of configuration parameters",
"complexity": "O(N) when N is the number of configuration parameters provided",
"group": "server",
"since": "2.0.0",
"arity": 3,
"container": "CONFIG",
"function": "configGetCommand",
"history": [
[
"7.0.0",
"Added the ability to pass multiple pattern parameters in one"
]
],
"command_flags": [
"ADMIN",
"NOSCRIPT",
"LOADING",
"STALE"
],
"arguments": [
{
"name": "parameter",
"type": "block",
"multiple": true,
"arguments": [
{
"name": "parameter",
"type": "string"
}
]
}
]
}
}
{
"HELP": {
"summary": "Show helpful text about the different subcommands",
"complexity": "O(1)",
"group": "server",
"since": "5.0.0",
"arity": 2,
"container": "CONFIG",
"function": "configHelpCommand",
"command_flags": [
"LOADING",
"STALE"
]
}
}
{
"RESETSTAT": {
"summary": "Reset the stats returned by INFO",
"complexity": "O(1)",
"group": "server",
"since": "2.0.0",
"arity": 2,
"container": "CONFIG",
"function": "configResetStatCommand",
"command_flags": [
"ADMIN",
"NOSCRIPT",
"STALE"
]
}
}
{
"REWRITE": {
"summary": "Rewrite the configuration file with the in memory configuration",
"complexity": "O(1)",
"group": "server",
"since": "2.8.0",
"arity": 2,
"container": "CONFIG",
"function": "configRewriteCommand",
"command_flags": [
"ADMIN",
"NOSCRIPT",
"STALE"
]
}
}
{
"SET": {
"summary": "Set configuration parameters to the given values",
"complexity": "O(N) when N is the number of configuration parameters provided",
"group": "server",
"since": "2.0.0",
"arity": -4,
"container": "CONFIG",
"function": "configSetCommand",
"history": [
[
"7.0.0",
"Added the ability to set multiple parameters in one call."
]
],
"command_flags": [
"ADMIN",
"NOSCRIPT",
"STALE"
],
"arguments": [
{
"name": "parameter_value",
"type": "block",
"multiple": true,
"arguments": [
{
"name": "parameter",
"type": "string"
},
{
"name": "value",
"type": "string"
}
]
}
]
}
}
{
"CONFIG": {
"summary": "A container for server configuration commands",
"complexity": "Depends on subcommand.",
"group": "server",
"since": "2.0.0",
"arity": -2
}
}
{
"COPY": {
"summary": "Copy a key",
"complexity": "O(N) worst case for collections, where N is the number of nested items. O(1) for string values.",
"group": "generic",
"since": "6.2.0",
"arity": -3,
"function": "copyCommand",
"command_flags": [
"WRITE",
"DENYOOM"
],
"acl_categories": [
"KEYSPACE"
],
"key_specs": [
{
"flags": [
"READ"
],
"begin_search": {
"index": {
"pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
},
{
"flags": [
"WRITE"
],
"begin_search": {
"index": {
"pos": 2
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
}
],
"arguments": [
{
"name": "source",
"type": "key",
"key_spec_index": 0
},
{
"name": "destination",
"type": "key",
"key_spec_index": 1
},
{
"token": "DB",
"name": "destination-db",
"type": "integer",
"optional": true
},
{
"name": "replace",
"token": "REPLACE",
"type": "pure-token",
"optional": true
}
]
}
}
{
"DBSIZE": {
"summary": "Return the number of keys in the selected database",
"complexity": "O(1)",
"group": "server",
"since": "1.0.0",
"arity": 1,
"function": "dbsizeCommand",
"command_flags": [
"READONLY",
"FAST"
],
"acl_categories": [
"KEYSPACE"
]
}
}
{
"DEBUG": {
"summary": "A container for debugging commands",
"complexity": "Depends on subcommand.",
"group": "server",
"since": "1.0.0",
"arity": -2,
"function": "debugCommand",
"doc_flags": [
"SYSCMD"
],
"command_flags": [
"ADMIN",
"NOSCRIPT",
"LOADING",
"STALE"
]
}
}
{
"DECR": {
"summary": "Decrement the integer value of a key by one",
"complexity": "O(1)",
"group": "string",
"since": "1.0.0",
"arity": 2,
"function": "decrCommand",
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
],
"acl_categories": [
"STRING"
],
"key_specs": [
{
"flags": [
"WRITE"
],
"begin_search": {
"index": {
"pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
}
],
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
}
]
}
}
{
"DECRBY": {
"summary": "Decrement the integer value of a key by the given number",
"complexity": "O(1)",
"group": "string",
"since": "1.0.0",
"arity": 3,
"function": "decrbyCommand",
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
],
"acl_categories": [
"STRING"
],
"key_specs": [
{
"flags": [
"WRITE"
],
"begin_search": {
"index": {
"pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
}
],
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"name": "decrement",
"type": "integer"
}
]
}
}
{
"DEL": {
"summary": "Delete a key",
"complexity": "O(N) where N is the number of keys that will be removed. When a key to remove holds a value other than a string, the individual complexity for this key is O(M) where M is the number of elements in the list, set, sorted set or hash. Removing a single key that holds a string value is O(1).",
"group": "generic",
"since": "1.0.0",
"arity": -2,
"function": "delCommand",
"command_flags": [
"WRITE"
],
"acl_categories": [
"KEYSPACE"
],
"key_specs": [
{
"flags": [
"WRITE"
],
"begin_search": {
"index": {
"pos": 1
}
},
"find_keys": {
"range": {
"lastkey": -1,
"step": 1,
"limit": 0
}
}
}
],
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0,
"multiple": true
}
]
}
}
{
"DISCARD": {
"summary": "Discard all commands issued after MULTI",
"complexity": "O(N), when N is the number of queued commands",
"group": "transactions",
"since": "2.0.0",
"arity": 1,
"function": "discardCommand",
"command_flags": [
"NOSCRIPT",
"LOADING",
"STALE",
"FAST"
],
"acl_categories": [
"TRANSACTION"
]
}
}
{
"DUMP": {
"summary": "Return a serialized version of the value stored at the specified key.",
"complexity": "O(1) to access the key and additional O(N*M) to serialize it, where N is the number of Redis objects composing the value and M their average size. For small string values the time complexity is thus O(1)+O(1*M) where M is small, so simply O(1).",
"group": "generic",
"since": "2.6.0",
"arity": 2,
"function": "dumpCommand",
"command_flags": [
"READONLY",
"RANDOM"
],
"acl_categories": [
"KEYSPACE"
],
"key_specs": [
{
"flags": [
"READ"
],
"begin_search": {
"index": {
"pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
}
],
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
}
]
}
}
{
"ECHO": {
"summary": "Echo the given string",
"complexity": "O(1)",
"group": "connection",
"since": "1.0.0",
"arity": 2,
"function": "echoCommand",
"command_flags": [
"FAST"
],
"acl_categories": [
"CONNECTION"
],
"arguments": [
{
"name": "message",
"type": "string"
}
]
}
}
{
"EVAL": {
"summary": "Execute a Lua script server side",
"complexity": "Depends on the script that is executed.",
"group": "scripting",
"since": "2.6.0",
"arity": -3,
"function": "evalCommand",
"get_keys_function": "evalGetKeys",
"command_flags": [
"NOSCRIPT",
"SKIP_MONITOR",
"MAY_REPLICATE",
"NO_MANDATORY_KEYS"
],
"acl_categories": [
"SCRIPTING"
],
"key_specs": [
{
"flags": [
"WRITE",
"READ"
],
"begin_search": {
"index": {
"pos": 2
}
},
"find_keys": {
"keynum": {
"keynumidx": 0,
"firstkey": 1,
"step": 1
}
}
}
],
"arguments": [
{
"name": "script",
"type": "string"
},
{
"name": "numkeys",
"type": "integer"
},
{
"name": "key",
"type": "key",
"key_spec_index": 0,
"optional": true,
"multiple": true
},
{
"name": "arg",
"type": "string",
"optional": true,
"multiple": true
}
]
}
}
{
"EVAL_RO": {
"summary": "Execute a read-only Lua script server side",
"complexity": "Depends on the script that is executed.",
"group": "scripting",
"since": "7.0.0",
"arity": -3,
"function": "evalRoCommand",
"get_keys_function": "evalGetKeys",
"command_flags": [
"NOSCRIPT",
"SKIP_MONITOR",
"NO_MANDATORY_KEYS"
],
"acl_categories": [
"SCRIPTING"
],
"key_specs": [
{
"flags": [
"READ"
],
"begin_search": {
"index": {
"pos": 2
}
},
"find_keys": {
"keynum": {
"keynumidx": 0,
"firstkey": 1,
"step": 1
}
}
}
],
"arguments": [
{
"name": "script",
"type": "string"
},
{
"name": "numkeys",
"type": "integer"
},
{
"name": "key",
"type": "key",
"key_spec_index": 0,
"multiple": true
},
{
"name": "arg",
"type": "string",
"multiple": true
}
]
}
}
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