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
{
"RPOPLPUSH": {
"summary": "Remove the last element in a list, prepend it to another list and return it",
"complexity": "O(1)",
"group": "list",
"since": "1.2.0",
"arity": 3,
"function": "rpoplpushCommand",
"deprecated_since": "6.2.0",
"replaced_by": "`LMOVE` with the `RIGHT` and `LEFT` arguments",
"doc_flags": [
"DEPRECATED"
],
"command_flags": [
"WRITE",
"DENYOOM"
],
"acl_categories": [
"LIST"
],
"key_specs": [
{
"flags": [
"WRITE",
"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
}
]
}
}
{
"RPUSH": {
"summary": "Append one or multiple elements to a list",
"complexity": "O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments.",
"group": "list",
"since": "1.0.0",
"arity": -3,
"function": "rpushCommand",
"history": [
[
"2.4",
"Accepts multiple `element` arguments."
]
],
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
],
"acl_categories": [
"LIST"
],
"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": "element",
"type": "string",
"multiple": true
}
]
}
}
{
"RPUSHX": {
"summary": "Append an element to a list, only if the list exists",
"complexity": "O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments.",
"group": "list",
"since": "2.2.0",
"arity": -3,
"function": "rpushxCommand",
"history": [
[
"4.0",
"Accepts multiple `element` arguments."
]
],
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
],
"acl_categories": [
"LIST"
],
"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": "element",
"type": "string",
"multiple": true
}
]
}
}
{
"SADD": {
"summary": "Add one or more members to a set",
"complexity": "O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments.",
"group": "set",
"since": "1.0.0",
"arity": -3,
"function": "saddCommand",
"history": [
[
"2.4",
"Accepts multiple `member` arguments."
]
],
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
],
"acl_categories": [
"SET"
],
"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": "member",
"type": "string",
"multiple": true
}
]
}
}
{
"SAVE": {
"summary": "Synchronously save the dataset to disk",
"complexity": "O(N) where N is the total number of keys in all databases",
"group": "server",
"since": "1.0.0",
"arity": 1,
"function": "saveCommand",
"command_flags": [
"ADMIN",
"NOSCRIPT"
]
}
}
{
"SCAN": {
"summary": "Incrementally iterate the keys space",
"complexity": "O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection.",
"group": "generic",
"since": "2.8.0",
"arity": -2,
"function": "scanCommand",
"command_flags": [
"READONLY",
"RANDOM"
],
"acl_categories": [
"KEYSPACE"
],
"arguments": [
{
"name": "cursor",
"type": "integer"
},
{
"token": "MATCH",
"name": "pattern",
"type": "pattern",
"optional": true
},
{
"token": "COUNT",
"name": "count",
"type": "integer",
"optional": true
},
{
"token": "TYPE",
"name": "type",
"type": "string",
"optional": true
}
]
}
}
{
"SCARD": {
"summary": "Get the number of members in a set",
"complexity": "O(1)",
"group": "set",
"since": "1.0.0",
"arity": 2,
"function": "scardCommand",
"command_flags": [
"READONLY",
"FAST"
],
"acl_categories": [
"SET"
],
"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
}
]
}
}
{
"DEBUG": {
"summary": "Set the debug mode for executed scripts.",
"complexity": "O(1)",
"group": "scripting",
"since": "3.2.0",
"arity": 3,
"container": "SCRIPT",
"function": "scriptCommand",
"command_flags": [
"NOSCRIPT"
],
"acl_categories": [
"SCRIPTING"
],
"arguments": [
{
"name": "mode",
"type": "oneof",
"arguments": [
{
"name": "yes",
"type": "pure-token",
"token": "YES"
},
{
"name": "sync",
"type": "pure-token",
"token": "SYNC"
},
{
"name": "no",
"type": "pure-token",
"token": "NO"
}
]
}
]
}
}
{
"EXISTS": {
"summary": "Check existence of scripts in the script cache.",
"complexity": "O(N) with N being the number of scripts to check (so checking a single script is an O(1) operation).",
"group": "scripting",
"since": "2.6.0",
"arity": -3,
"container": "SCRIPT",
"function": "scriptCommand",
"command_flags": [
"NOSCRIPT"
],
"acl_categories": [
"SCRIPTING"
],
"arguments": [
{
"name": "sha1",
"type": "string",
"multiple": true
}
]
}
}
{
"FLUSH": {
"summary": "Remove all the scripts from the script cache.",
"complexity": "O(N) with N being the number of scripts in cache",
"group": "scripting",
"since": "2.6.0",
"arity": -2,
"container": "SCRIPT",
"function": "scriptCommand",
"history": [
[
"6.2.0",
"Added the `ASYNC` and `SYNC` flushing mode modifiers, as well as the **lazyfree-lazy-user-flush** configuration directive."
]
],
"command_flags": [
"NOSCRIPT",
"MAY_REPLICATE"
],
"acl_categories": [
"SCRIPTING"
],
"arguments": [
{
"name": "async",
"type": "oneof",
"optional": true,
"arguments": [
{
"name": "async",
"type": "pure-token",
"token": "ASYNC"
},
{
"name": "sync",
"type": "pure-token",
"token": "SYNC"
}
]
}
]
}
}
{
"HELP": {
"summary": "Show helpful text about the different subcommands",
"complexity": "O(1)",
"group": "scripting",
"since": "5.0.0",
"arity": 2,
"container": "SCRIPT",
"function": "scriptCommand",
"command_flags": [
"LOADING",
"STALE"
],
"acl_categories": [
"SCRIPTING"
]
}
}
{
"KILL": {
"summary": "Kill the script currently in execution.",
"complexity": "O(1)",
"group": "scripting",
"since": "2.6.0",
"arity": 2,
"container": "SCRIPT",
"function": "scriptCommand",
"command_flags": [
"NOSCRIPT"
],
"acl_categories": [
"SCRIPTING"
]
}
}
{
"LOAD": {
"summary": "Load the specified Lua script into the script cache.",
"complexity": "O(N) with N being the length in bytes of the script body.",
"group": "scripting",
"since": "2.6.0",
"arity": 3,
"container": "SCRIPT",
"function": "scriptCommand",
"command_flags": [
"NOSCRIPT",
"MAY_REPLICATE"
],
"acl_categories": [
"SCRIPTING"
],
"arguments": [
{
"name": "script",
"type": "string"
}
]
}
}
{
"SCRIPT": {
"summary": "A container for Lua scripts management commands",
"complexity": "Depends on subcommand.",
"group": "scripting",
"since": "2.6.0",
"arity": -2
}
}
{
"SDIFF": {
"summary": "Subtract multiple sets",
"complexity": "O(N) where N is the total number of elements in all given sets.",
"group": "set",
"since": "1.0.0",
"arity": -2,
"function": "sdiffCommand",
"command_flags": [
"READONLY",
"SORT_FOR_SCRIPT"
],
"acl_categories": [
"SET"
],
"key_specs": [
{
"flags": [
"READ"
],
"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
}
]
}
}
{
"SDIFFSTORE": {
"summary": "Subtract multiple sets and store the resulting set in a key",
"complexity": "O(N) where N is the total number of elements in all given sets.",
"group": "set",
"since": "1.0.0",
"arity": -3,
"function": "sdiffstoreCommand",
"command_flags": [
"WRITE",
"DENYOOM"
],
"acl_categories": [
"SET"
],
"key_specs": [
{
"flags": [
"WRITE"
],
"begin_search": {
"index": {
"pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
},
{
"flags": [
"READ"
],
"begin_search": {
"index": {
"pos": 2
}
},
"find_keys": {
"range": {
"lastkey": -1,
"step": 1,
"limit": 0
}
}
}
],
"arguments": [
{
"name": "destination",
"type": "key",
"key_spec_index": 0
},
{
"name": "key",
"type": "key",
"key_spec_index": 1,
"multiple": true
}
]
}
}
{
"SELECT": {
"summary": "Change the selected database for the current connection",
"complexity": "O(1)",
"group": "connection",
"since": "1.0.0",
"arity": 2,
"function": "selectCommand",
"command_flags": [
"LOADING",
"STALE",
"FAST"
],
"acl_categories": [
"CONNECTION"
],
"arguments": [
{
"name": "index",
"type": "integer"
}
]
}
}
{
"CKQUORUM": {
"summary": "Check for a Sentinel quorum",
"group": "sentinel",
"since": "2.8.4",
"arity": 3,
"container": "SENTINEL",
"function": "sentinelCommand",
"command_flags": [
"ADMIN",
"SENTINEL",
"ONLY_SENTINEL"
]
}
}
{
"CONFIG": {
"summary": "Configure Sentinel",
"complexity": "O(1)",
"group": "sentinel",
"since": "6.2.0",
"arity": -3,
"container": "SENTINEL",
"function": "sentinelCommand",
"command_flags": [
"ADMIN",
"SENTINEL",
"ONLY_SENTINEL"
]
}
}
{
"DEBUG": {
"group": "sentinel",
"since": "7.0.0",
"arity": -2,
"container": "SENTINEL",
"function": "sentinelCommand",
"command_flags": [
"ADMIN",
"SENTINEL",
"ONLY_SENTINEL"
]
}
}
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