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
{
"HGETALL": {
"summary": "Get all the fields and values in a hash",
"complexity": "O(N) where N is the size of the hash.",
"group": "hash",
"since": "2.0.0",
"arity": 2,
"function": "hgetallCommand",
"command_flags": [
"READONLY",
"RANDOM"
],
"acl_categories": [
"HASH"
],
"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
}
]
}
}
{
"HINCRBY": {
"summary": "Increment the integer value of a hash field by the given number",
"complexity": "O(1)",
"group": "hash",
"since": "2.0.0",
"arity": 4,
"function": "hincrbyCommand",
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
],
"acl_categories": [
"HASH"
],
"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": "field",
"type": "string"
},
{
"name": "increment",
"type": "integer"
}
]
}
}
{
"HINCRBYFLOAT": {
"summary": "Increment the float value of a hash field by the given amount",
"complexity": "O(1)",
"group": "hash",
"since": "2.6.0",
"arity": 4,
"function": "hincrbyfloatCommand",
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
],
"acl_categories": [
"HASH"
],
"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": "field",
"type": "string"
},
{
"name": "increment",
"type": "double"
}
]
}
}
{
"HKEYS": {
"summary": "Get all the fields in a hash",
"complexity": "O(N) where N is the size of the hash.",
"group": "hash",
"since": "2.0.0",
"arity": 2,
"function": "hkeysCommand",
"command_flags": [
"READONLY",
"SORT_FOR_SCRIPT"
],
"acl_categories": [
"HASH"
],
"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
}
]
}
}
{
"HLEN": {
"summary": "Get the number of fields in a hash",
"complexity": "O(1)",
"group": "hash",
"since": "2.0.0",
"arity": 2,
"function": "hlenCommand",
"command_flags": [
"READONLY",
"FAST"
],
"acl_categories": [
"HASH"
],
"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
}
]
}
}
{
"HMGET": {
"summary": "Get the values of all the given hash fields",
"complexity": "O(N) where N is the number of fields being requested.",
"group": "hash",
"since": "2.0.0",
"arity": -3,
"function": "hmgetCommand",
"command_flags": [
"READONLY",
"FAST"
],
"acl_categories": [
"HASH"
],
"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": "field",
"type": "string",
"multiple": true
}
]
}
}
{
"HMSET": {
"summary": "Set multiple hash fields to multiple values",
"complexity": "O(N) where N is the number of fields being set.",
"group": "hash",
"since": "2.0.0",
"arity": -4,
"function": "hsetCommand",
"deprecated_since": "4.0.0",
"replaced_by": "`HSET` with multiple field-value pairs",
"doc_flags": [
"DEPRECATED"
],
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
],
"acl_categories": [
"HASH"
],
"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": "field_value",
"type": "block",
"multiple": true,
"arguments": [
{
"name": "field",
"type": "string"
},
{
"name": "value",
"type": "string"
}
]
}
]
}
}
{
"HRANDFIELD": {
"summary": "Get one or multiple random fields from a hash",
"complexity": "O(N) where N is the number of fields returned",
"group": "hash",
"since": "6.2.0",
"arity": -2,
"function": "hrandfieldCommand",
"command_flags": [
"READONLY",
"RANDOM"
],
"acl_categories": [
"HASH"
],
"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": "options",
"type": "block",
"optional": true,
"arguments": [
{
"name": "count",
"type": "integer"
},
{
"name": "withvalues",
"token": "WITHVALUES",
"type": "pure-token",
"optional": true
}
]
}
]
}
}
{
"HSCAN": {
"summary": "Incrementally iterate hash fields and associated values",
"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": "hash",
"since": "2.8.0",
"arity": -3,
"function": "hscanCommand",
"command_flags": [
"READONLY",
"RANDOM"
],
"acl_categories": [
"HASH"
],
"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
}
]
}
}
{
"HSET": {
"summary": "Set the string value of a hash field",
"complexity": "O(1) for each field/value pair added, so O(N) to add N field/value pairs when the command is called with multiple field/value pairs.",
"group": "hash",
"since": "2.0.0",
"arity": -4,
"function": "hsetCommand",
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
],
"acl_categories": [
"HASH"
],
"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": "field_value",
"type": "block",
"multiple": true,
"arguments": [
{
"name": "field",
"type": "string"
},
{
"name": "value",
"type": "string"
}
]
}
]
}
}
{
"HSETNX": {
"summary": "Set the value of a hash field, only if the field does not exist",
"complexity": "O(1)",
"group": "hash",
"since": "2.0.0",
"arity": 4,
"function": "hsetnxCommand",
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
],
"acl_categories": [
"HASH"
],
"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": "field",
"type": "string"
},
{
"name": "value",
"type": "string"
}
]
}
}
{
"HSTRLEN": {
"summary": "Get the length of the value of a hash field",
"complexity": "O(1)",
"group": "hash",
"since": "3.2.0",
"arity": 3,
"function": "hstrlenCommand",
"command_flags": [
"READONLY",
"FAST"
],
"acl_categories": [
"HASH"
],
"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": "field",
"type": "string"
}
]
}
}
{
"HVALS": {
"summary": "Get all the values in a hash",
"complexity": "O(N) where N is the size of the hash.",
"group": "hash",
"since": "2.0.0",
"arity": 2,
"function": "hvalsCommand",
"command_flags": [
"READONLY",
"SORT_FOR_SCRIPT"
],
"acl_categories": [
"HASH"
],
"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
}
]
}
}
{
"INCR": {
"summary": "Increment the integer value of a key by one",
"complexity": "O(1)",
"group": "string",
"since": "1.0.0",
"arity": 2,
"function": "incrCommand",
"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
}
]
}
}
{
"INCRBY": {
"summary": "Increment the integer value of a key by the given amount",
"complexity": "O(1)",
"group": "string",
"since": "1.0.0",
"arity": 3,
"function": "incrbyCommand",
"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": "increment",
"type": "integer"
}
]
}
}
{
"INCRBYFLOAT": {
"summary": "Increment the float value of a key by the given amount",
"complexity": "O(1)",
"group": "string",
"since": "2.6.0",
"arity": 3,
"function": "incrbyfloatCommand",
"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": "increment",
"type": "double"
}
]
}
}
{
"INFO": {
"summary": "Get information and statistics about the server",
"complexity": "O(1)",
"group": "server",
"since": "1.0.0",
"arity": -1,
"function": "infoCommand",
"command_flags": [
"RANDOM",
"LOADING",
"STALE",
"SENTINEL"
],
"acl_categories": [
"DANGEROUS"
],
"arguments": [
{
"name": "section",
"type": "string",
"optional": true
}
]
}
}
{
"KEYS": {
"summary": "Find all keys matching the given pattern",
"complexity": "O(N) with N being the number of keys in the database, under the assumption that the key names in the database and the given pattern have limited length.",
"group": "generic",
"since": "1.0.0",
"arity": 2,
"function": "keysCommand",
"command_flags": [
"READONLY",
"SORT_FOR_SCRIPT"
],
"acl_categories": [
"KEYSPACE",
"DANGEROUS"
],
"arguments": [
{
"name": "pattern",
"type": "pattern"
}
]
}
}
{
"LASTSAVE": {
"summary": "Get the UNIX time stamp of the last successful save to disk",
"complexity": "O(1)",
"group": "server",
"since": "1.0.0",
"arity": 1,
"function": "lastsaveCommand",
"command_flags": [
"RANDOM",
"LOADING",
"STALE",
"FAST"
],
"acl_categories": [
"ADMIN",
"DANGEROUS"
]
}
}
{
"DOCTOR": {
"summary": "Return a human readable latency analysis report.",
"complexity": "O(1)",
"group": "server",
"since": "2.8.13",
"arity": 2,
"container": "LATENCY",
"function": "latencyCommand",
"command_flags": [
"ADMIN",
"NOSCRIPT",
"LOADING",
"STALE"
]
}
}
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