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
{
"SETEX": {
"summary": "Set the value and expiration of a key",
"complexity": "O(1)",
"group": "string",
"since": "2.0.0",
"arity": 4,
"function": "setexCommand",
"command_flags": [
"WRITE",
"DENYOOM"
],
"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": "seconds",
"type": "integer"
},
{
"name": "value",
"type": "string"
}
]
}
}
{
"SETNX": {
"summary": "Set the value of a key, only if the key does not exist",
"complexity": "O(1)",
"group": "string",
"since": "1.0.0",
"arity": 3,
"function": "setnxCommand",
"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": "value",
"type": "string"
}
]
}
}
{
"SETRANGE": {
"summary": "Overwrite part of a string at key starting at the specified offset",
"complexity": "O(1), not counting the time taken to copy the new string in place. Usually, this string is very small so the amortized complexity is O(1). Otherwise, complexity is O(M) with M being the length of the value argument.",
"group": "string",
"since": "2.2.0",
"arity": 4,
"function": "setrangeCommand",
"command_flags": [
"WRITE",
"DENYOOM"
],
"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": "offset",
"type": "integer"
},
{
"name": "value",
"type": "string"
}
]
}
}
{
"SHUTDOWN": {
"summary": "Synchronously save the dataset to disk and then shut down the server",
"group": "server",
"since": "1.0.0",
"arity": -1,
"function": "shutdownCommand",
"command_flags": [
"ADMIN",
"NOSCRIPT",
"LOADING",
"STALE",
"SENTINEL"
],
"arguments": [
{
"name": "nosave_save",
"type": "oneof",
"optional": true,
"arguments": [
{
"name": "nosave",
"type": "pure-token",
"token": "NOSAVE"
},
{
"name": "save",
"type": "pure-token",
"token": "SAVE"
}
]
}
]
}
}
{
"SINTER": {
"summary": "Intersect multiple sets",
"complexity": "O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets.",
"group": "set",
"since": "1.0.0",
"arity": -2,
"function": "sinterCommand",
"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
}
]
}
}
{
"SINTERCARD": {
"summary": "Intersect multiple sets and return the cardinality of the result",
"complexity": "O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets.",
"group": "set",
"since": "7.0.0",
"arity": -3,
"function": "sinterCardCommand",
"get_keys_function": "sintercardGetKeys",
"command_flags": [
"READONLY"
],
"acl_categories": [
"SET"
],
"key_specs": [
{
"flags": [
"READ"
],
"begin_search": {
"index": {
"pos": 1
}
},
"find_keys": {
"keynum": {
"keynumidx": 0,
"firstkey": 1,
"step": 1
}
}
}
],
"arguments": [
{
"name": "numkeys",
"type": "integer"
},
{
"name": "key",
"type": "key",
"key_spec_index": 0,
"multiple": true
},
{
"token": "LIMIT",
"name": "limit",
"type": "integer",
"optional": true
}
]
}
}
{
"SINTERSTORE": {
"summary": "Intersect multiple sets and store the resulting set in a key",
"complexity": "O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets.",
"group": "set",
"since": "1.0.0",
"arity": -3,
"function": "sinterstoreCommand",
"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
}
]
}
}
{
"SISMEMBER": {
"summary": "Determine if a given value is a member of a set",
"complexity": "O(1)",
"group": "set",
"since": "1.0.0",
"arity": 3,
"function": "sismemberCommand",
"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
},
{
"name": "member",
"type": "string"
}
]
}
}
{
"SLAVEOF": {
"summary": "Make the server a replica of another instance, or promote it as master. Deprecated starting with Redis 5. Use REPLICAOF instead.",
"complexity": "O(1)",
"group": "server",
"since": "1.0.0",
"arity": 3,
"function": "replicaofCommand",
"command_flags": [
"ADMIN",
"NOSCRIPT",
"STALE"
],
"arguments": [
{
"name": "host",
"type": "string"
},
{
"name": "port",
"type": "string"
}
]
}
}
{
"GET": {
"summary": "Get the slow log's entries",
"complexity": "O(N) where N is the number of entries returned",
"group": "server",
"since": "2.2.12",
"arity": -2,
"container": "SLOWLOG",
"function": "slowlogCommand",
"history": [
[
"4.0",
"Added client IP address, port and name to the reply."
]
],
"command_flags": [
"ADMIN",
"RANDOM",
"LOADING",
"STALE"
],
"arguments": [
{
"name": "count",
"type": "integer",
"optional": true
}
]
}
}
{
"HELP": {
"summary": "Show helpful text about the different subcommands",
"complexity": "O(1)",
"group": "server",
"since": "6.2.0",
"arity": 2,
"container": "SLOWLOG",
"function": "slowlogCommand",
"command_flags": [
"LOADING",
"STALE"
]
}
}
{
"LEN": {
"summary": "Get the slow log's length",
"complexity": "O(1)",
"group": "server",
"since": "2.2.12",
"arity": 2,
"container": "SLOWLOG",
"function": "slowlogCommand",
"command_flags": [
"ADMIN",
"RANDOM",
"LOADING",
"STALE"
]
}
}
{
"RESET": {
"summary": "Clear all entries from the slow log",
"complexity": "O(N) where N is the number of entries in the slowlog",
"group": "server",
"since": "2.2.12",
"arity": 2,
"container": "SLOWLOG",
"function": "slowlogCommand",
"command_flags": [
"ADMIN",
"LOADING",
"STALE"
]
}
}
{
"SLOWLOG": {
"summary": "A container for slow log commands",
"complexity": "Depends on subcommand.",
"group": "server",
"since": "2.2.12",
"arity": -2
}
}
{
"SMEMBERS": {
"summary": "Get all the members in a set",
"complexity": "O(N) where N is the set cardinality.",
"group": "set",
"since": "1.0.0",
"arity": 2,
"function": "sinterCommand",
"command_flags": [
"READONLY",
"SORT_FOR_SCRIPT"
],
"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
}
]
}
}
{
"SMISMEMBER": {
"summary": "Returns the membership associated with the given elements for a set",
"complexity": "O(N) where N is the number of elements being checked for membership",
"group": "set",
"since": "6.2.0",
"arity": -3,
"function": "smismemberCommand",
"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
},
{
"name": "member",
"type": "string",
"multiple": true
}
]
}
}
{
"SMOVE": {
"summary": "Move a member from one set to another",
"complexity": "O(1)",
"group": "set",
"since": "1.0.0",
"arity": 4,
"function": "smoveCommand",
"command_flags": [
"WRITE",
"FAST"
],
"acl_categories": [
"SET"
],
"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
},
{
"name": "member",
"type": "string"
}
]
}
}
{
"SORT": {
"summary": "Sort the elements in a list, set or sorted set",
"complexity": "O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is O(N).",
"group": "generic",
"since": "1.0.0",
"arity": -2,
"function": "sortCommand",
"get_keys_function": "sortGetKeys",
"command_flags": [
"WRITE",
"DENYOOM"
],
"acl_categories": [
"SET",
"SORTEDSET",
"LIST",
"DANGEROUS"
],
"key_specs": [
{
"flags": [
"READ"
],
"begin_search": {
"index": {
"pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
},
{
"flags": [
"WRITE",
"INCOMPLETE"
],
"begin_search": {
"unknown": null
},
"find_keys": {
"unknown": null
}
}
],
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"token": "BY",
"name": "pattern",
"type": "pattern",
"optional": true
},
{
"token": "LIMIT",
"name": "offset_count",
"type": "block",
"optional": true,
"arguments": [
{
"name": "offset",
"type": "integer"
},
{
"name": "count",
"type": "integer"
}
]
},
{
"token": "GET",
"name": "pattern",
"type": "string",
"optional": true,
"multiple": true,
"multiple_token": true
},
{
"name": "order",
"type": "oneof",
"optional": true,
"arguments": [
{
"name": "asc",
"type": "pure-token",
"token": "ASC"
},
{
"name": "desc",
"type": "pure-token",
"token": "DESC"
}
]
},
{
"name": "sorting",
"token": "ALPHA",
"type": "pure-token",
"optional": true
},
{
"token": "STORE",
"name": "destination",
"type": "key",
"key_spec_index": 1,
"optional": true
}
]
}
}
{
"SORT_RO": {
"summary": "Sort the elements in a list, set or sorted set. Read-only variant of SORT.",
"complexity": "O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is O(N).",
"group": "generic",
"since": "7.0.0",
"arity": -2,
"function": "sortroCommand",
"command_flags": [
"READONLY"
],
"acl_categories": [
"SET",
"SORTEDSET",
"LIST",
"DANGEROUS"
],
"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
},
{
"token": "BY",
"name": "pattern",
"type": "pattern",
"optional": true
},
{
"token": "LIMIT",
"name": "offset_count",
"type": "block",
"optional": true,
"arguments": [
{
"name": "offset",
"type": "integer"
},
{
"name": "count",
"type": "integer"
}
]
},
{
"token": "GET",
"name": "pattern",
"type": "string",
"optional": true,
"multiple": true,
"multiple_token": true
},
{
"name": "order",
"type": "oneof",
"optional": true,
"arguments": [
{
"name": "asc",
"type": "pure-token",
"token": "ASC"
},
{
"name": "desc",
"type": "pure-token",
"token": "DESC"
}
]
},
{
"name": "sorting",
"token": "ALPHA",
"type": "pure-token",
"optional": true
}
]
}
}
{
"SPOP": {
"summary": "Remove and return one or multiple random members from a set",
"complexity": "Without the count argument O(1), otherwise O(N) where N is the value of the passed count.",
"group": "set",
"since": "1.0.0",
"arity": -2,
"function": "spopCommand",
"history": [
[
"3.2",
"Added the `count` argument."
]
],
"command_flags": [
"WRITE",
"RANDOM",
"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": "count",
"type": "integer",
"optional": 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