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
{
"SRANDMEMBER": {
"summary": "Get one or multiple random members from a set",
"complexity": "Without the count argument O(1), otherwise O(N) where N is the absolute value of the passed count.",
"group": "set",
"since": "1.0.0",
"arity": -2,
"function": "srandmemberCommand",
"history": [
[
"2.6.0",
"Added the optional `count` argument."
]
],
"command_flags": [
"READONLY",
"RANDOM"
],
"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
},
{
"name": "count",
"type": "integer",
"optional": true
}
]
}
}
{
"SREM": {
"summary": "Remove one or more members from a set",
"complexity": "O(N) where N is the number of members to be removed.",
"group": "set",
"since": "1.0.0",
"arity": -3,
"function": "sremCommand",
"history": [
[
"2.4",
"Accepts multiple `member` arguments."
]
],
"command_flags": [
"WRITE",
"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
}
]
}
}
{
"SSCAN": {
"summary": "Incrementally iterate Set elements",
"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": "set",
"since": "2.8.0",
"arity": -3,
"function": "sscanCommand",
"command_flags": [
"READONLY",
"RANDOM"
],
"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
},
{
"name": "cursor",
"type": "integer"
},
{
"token": "MATCH",
"name": "pattern",
"type": "pattern",
"optional": true
},
{
"token": "COUNT",
"name": "count",
"type": "integer",
"optional": true
}
]
}
}
{
"STRLEN": {
"summary": "Get the length of the value stored in a key",
"complexity": "O(1)",
"group": "string",
"since": "2.2.0",
"arity": 2,
"function": "strlenCommand",
"command_flags": [
"READONLY",
"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
}
]
}
}
{
"SUBSCRIBE": {
"summary": "Listen for messages published to the given channels",
"complexity": "O(N) where N is the number of channels to subscribe to.",
"group": "pubsub",
"since": "2.0.0",
"arity": -2,
"function": "subscribeCommand",
"history": [
[
"6.2",
"`RESET` can be called to exit subscribed state."
]
],
"command_flags": [
"PUBSUB",
"NOSCRIPT",
"LOADING",
"STALE",
"SENTINEL"
],
"arguments": [
{
"name": "channel",
"type": "string",
"multiple": true
}
]
}
}
{
"SUBSTR": {
"summary": "Get a substring of the string stored at a key",
"complexity": "O(N) where N is the length of the returned string. The complexity is ultimately determined by the returned length, but because creating a substring from an existing string is very cheap, it can be considered O(1) for small strings.",
"group": "string",
"since": "1.0.0",
"arity": 4,
"function": "getrangeCommand",
"deprecated_since": "2.0.0",
"replaced_by": "`GETRANGE`",
"doc_flags": [
"DEPRECATED"
],
"command_flags": [
"READONLY"
],
"acl_categories": [
"STRING"
],
"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
},
{
"name": "start",
"type": "integer"
},
{
"name": "end",
"type": "integer"
}
]
}
}
{
"SUNION": {
"summary": "Add 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": "sunionCommand",
"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
}
]
}
}
{
"SUNIONSTORE": {
"summary": "Add 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": "sunionstoreCommand",
"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
}
]
}
}
{
"SWAPDB": {
"summary": "Swaps two Redis databases",
"complexity": "O(N) where N is the count of clients watching or blocking on keys from both databases.",
"group": "server",
"since": "4.0.0",
"arity": 3,
"function": "swapdbCommand",
"command_flags": [
"WRITE",
"FAST"
],
"acl_categories": [
"KEYSPACE",
"DANGEROUS"
],
"arguments": [
{
"name": "index1",
"type": "integer"
},
{
"name": "index2",
"type": "integer"
}
]
}
}
{
"SYNC": {
"summary": "Internal command used for replication",
"group": "server",
"since": "1.0.0",
"arity": 1,
"function": "syncCommand",
"command_flags": [
"ADMIN",
"NOSCRIPT"
]
}
}
{
"TIME": {
"summary": "Return the current server time",
"complexity": "O(1)",
"group": "server",
"since": "2.6.0",
"arity": 1,
"function": "timeCommand",
"command_flags": [
"RANDOM",
"LOADING",
"STALE",
"FAST"
]
}
}
{
"TOUCH": {
"summary": "Alters the last access time of a key(s). Returns the number of existing keys specified.",
"complexity": "O(N) where N is the number of keys that will be touched.",
"group": "generic",
"since": "3.2.1",
"arity": -2,
"function": "touchCommand",
"command_flags": [
"READONLY",
"FAST"
],
"acl_categories": [
"KEYSPACE"
],
"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
}
]
}
}
{
"TTL": {
"summary": "Get the time to live for a key in seconds",
"complexity": "O(1)",
"group": "generic",
"since": "1.0.0",
"arity": 2,
"function": "ttlCommand",
"command_flags": [
"READONLY",
"RANDOM",
"FAST"
],
"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
}
]
}
}
{
"TYPE": {
"summary": "Determine the type stored at key",
"complexity": "O(1)",
"group": "generic",
"since": "1.0.0",
"arity": 2,
"function": "typeCommand",
"command_flags": [
"READONLY",
"FAST"
],
"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
}
]
}
}
{
"UNLINK": {
"summary": "Delete a key asynchronously in another thread. Otherwise it is just as DEL, but non blocking.",
"complexity": "O(1) for each key removed regardless of its size. Then the command does O(N) work in a different thread in order to reclaim memory, where N is the number of allocations the deleted objects where composed of.",
"group": "generic",
"since": "4.0.0",
"arity": -2,
"function": "unlinkCommand",
"command_flags": [
"WRITE",
"FAST"
],
"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
}
]
}
}
{
"UNSUBSCRIBE": {
"summary": "Stop listening for messages posted to the given channels",
"complexity": "O(N) where N is the number of clients already subscribed to a channel.",
"group": "pubsub",
"since": "2.0.0",
"arity": -1,
"function": "unsubscribeCommand",
"command_flags": [
"PUBSUB",
"NOSCRIPT",
"LOADING",
"STALE",
"SENTINEL"
],
"arguments": [
{
"name": "channel",
"type": "string",
"optional": true,
"multiple": true
}
]
}
}
{
"UNWATCH": {
"summary": "Forget about all watched keys",
"complexity": "O(1)",
"group": "transactions",
"since": "2.2.0",
"arity": 1,
"function": "unwatchCommand",
"command_flags": [
"NOSCRIPT",
"LOADING",
"STALE",
"FAST"
],
"acl_categories": [
"TRANSACTION"
]
}
}
{
"WAIT": {
"summary": "Wait for the synchronous replication of all the write commands sent in the context of the current connection",
"complexity": "O(1)",
"group": "generic",
"since": "3.0.0",
"arity": 3,
"function": "waitCommand",
"command_flags": [
"NOSCRIPT"
],
"acl_categories": [
"CONNECTION"
],
"arguments": [
{
"name": "numreplicas",
"type": "integer"
},
{
"name": "timeout",
"type": "integer"
}
]
}
}
{
"WATCH": {
"summary": "Watch the given keys to determine execution of the MULTI/EXEC block",
"complexity": "O(1) for every key.",
"group": "transactions",
"since": "2.2.0",
"arity": -2,
"function": "watchCommand",
"command_flags": [
"NOSCRIPT",
"LOADING",
"STALE",
"FAST"
],
"acl_categories": [
"TRANSACTION"
],
"key_specs": [
{
"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
}
]
}
}
{
"XACK": {
"summary": "Marks a pending message as correctly processed, effectively removing it from the pending entries list of the consumer group. Return value of the command is the number of messages successfully acknowledged, that is, the IDs we were actually able to resolve in the PEL.",
"complexity": "O(1) for each message ID processed.",
"group": "stream",
"since": "5.0.0",
"arity": -4,
"function": "xackCommand",
"command_flags": [
"WRITE",
"RANDOM",
"FAST"
],
"acl_categories": [
"STREAM"
],
"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": "group",
"type": "string"
},
{
"name": "ID",
"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