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

Repurpose redisCommandArg's name as the unique ID (#11051)

This PR makes sure that "name" is unique for all arguments in the same
level (i.e. all args of a command and all args within a block/oneof).
This means several argument with identical meaning can be referred to together,
but also if someone needs to refer to a specific one, they can use its full path.

In addition, the "display_text" field has been added, to be used by redis.io
in order to render the syntax of the command (for the vast majority it is
identical to "name" but sometimes we want to use a different string
that is not "name")
The "display" field is exposed via COMMAND DOCS and will be present
for every argument, except "oneof" and "block" (which are container
arguments)

Other changes:
1. Make sure we do not have any container arguments ("oneof" or "block")
   that contain less than two sub-args (otherwise it doesn't make sense)
2. migrate.json: both AUTH and AUTH2 should not be "optional"
3. arg names cannot contain underscores, and force the usage of hyphens
  (most of these were a result of the script that generated the initial json files
  from redis.io commands.json). 
parent fc3956e8
......@@ -71,14 +71,15 @@
},
{
"token": "BY",
"name": "pattern",
"name": "by-pattern",
"display": "pattern",
"type": "pattern",
"key_spec_index": 1,
"optional": true
},
{
"token": "LIMIT",
"name": "offset_count",
"name": "limit",
"type": "block",
"optional": true,
"arguments": [
......@@ -94,7 +95,8 @@
},
{
"token": "GET",
"name": "pattern",
"name": "get-pattern",
"display": "pattern",
"key_spec_index": 1,
"type": "pattern",
"optional": true,
......
......@@ -57,14 +57,15 @@
},
{
"token": "BY",
"name": "pattern",
"name": "by-pattern",
"display": "pattern",
"type": "pattern",
"key_spec_index": 1,
"optional": true
},
{
"token": "LIMIT",
"name": "offset_count",
"name": "limit",
"type": "block",
"optional": true,
"arguments": [
......@@ -80,7 +81,8 @@
},
{
"token": "GET",
"name": "pattern",
"name": "get-pattern",
"display": "pattern",
"key_spec_index": 1,
"type": "pattern",
"optional": true,
......
......@@ -114,22 +114,22 @@
]
},
{
"name": "id_or_auto",
"name": "id-selector",
"type": "oneof",
"arguments": [
{
"name": "auto_id",
"name": "auto-id",
"type": "pure-token",
"token": "*"
},
{
"name": "ID",
"name": "id",
"type": "string"
}
]
},
{
"name": "field_value",
"name": "data",
"type": "block",
"multiple": true,
"arguments": [
......
......@@ -90,7 +90,7 @@
"optional": true
},
{
"name": "id",
"name": "lastid",
"token": "LASTID",
"type": "string",
"optional": true
......
......@@ -51,15 +51,15 @@
"type": "string"
},
{
"name": "id",
"name": "id-selector",
"type": "oneof",
"arguments": [
{
"name": "ID",
"name": "id",
"type": "string"
},
{
"name": "new_id",
"name": "new-id",
"type": "pure-token",
"token": "$"
}
......@@ -73,7 +73,7 @@
},
{
"token": "ENTRIESREAD",
"name": "entries_read",
"name": "entries-read",
"type": "integer",
"optional": true
}
......
......@@ -50,22 +50,23 @@
"type": "string"
},
{
"name": "id",
"name": "id-selector",
"type": "oneof",
"arguments": [
{
"name": "ID",
"name": "id",
"type": "string"
},
{
"name": "new_id",
"name": "new-id",
"type": "pure-token",
"token": "$"
}
]
},
{
"name": "entries_read",
"name": "entriesread",
"display": "entries-read",
"token": "ENTRIESREAD",
"type": "integer",
"optional": true
......
......@@ -50,11 +50,15 @@
"key_spec_index": 0
},
{
"name": "full",
"token": "FULL",
"name": "full-block",
"type": "block",
"optional": true,
"arguments": [
{
"name": "full",
"token": "FULL",
"type": "pure-token"
},
{
"token": "COUNT",
"name": "count",
......
......@@ -38,7 +38,7 @@
"arguments": [
{
"token": "GROUP",
"name": "group_consumer",
"name": "group-block",
"type": "block",
"arguments": [
{
......
......@@ -51,13 +51,13 @@
"type": "string"
},
{
"name": "entries_added",
"name": "entries-added",
"token": "ENTRIESADDED",
"type": "integer",
"optional": true
},
{
"name": "max_deleted_entry_id",
"name": "max-deleted-id",
"token": "MAXDELETEDID",
"type": "string",
"optional": true
......
......@@ -105,7 +105,7 @@
"since": "3.0.2"
},
{
"name": "score_member",
"name": "data",
"type": "block",
"multiple": true,
"arguments": [
......
......@@ -79,7 +79,7 @@
},
{
"token": "LIMIT",
"name": "offset_count",
"name": "limit",
"type": "block",
"optional": true,
"since": "6.2.0",
......
......@@ -53,7 +53,7 @@
},
{
"token": "LIMIT",
"name": "offset_count",
"name": "limit",
"type": "block",
"optional": true,
"arguments": [
......
......@@ -66,7 +66,7 @@
},
{
"token": "LIMIT",
"name": "offset_count",
"name": "limit",
"type": "block",
"optional": true,
"arguments": [
......
......@@ -95,7 +95,7 @@
},
{
"token": "LIMIT",
"name": "offset_count",
"name": "limit",
"type": "block",
"optional": true,
"arguments": [
......
......@@ -53,7 +53,7 @@
},
{
"token": "LIMIT",
"name": "offset_count",
"name": "limit",
"type": "block",
"optional": true,
"arguments": [
......
......@@ -65,7 +65,7 @@
},
{
"token": "LIMIT",
"name": "offset_count",
"name": "limit",
"type": "block",
"optional": true,
"arguments": [
......
......@@ -1927,6 +1927,7 @@ static struct redisCommandArg *moduleCopyCommandArgs(RedisModuleCommandArg *args
if (arg->summary) realargs[j].summary = zstrdup(arg->summary);
if (arg->since) realargs[j].since = zstrdup(arg->since);
if (arg->deprecated_since) realargs[j].deprecated_since = zstrdup(arg->deprecated_since);
if (arg->display_text) realargs[j].display_text = zstrdup(arg->display_text);
realargs[j].flags = moduleConvertArgFlags(arg->flags);
if (arg->subargs) realargs[j].subargs = moduleCopyCommandArgs(arg->subargs, version);
}
......@@ -11046,6 +11047,7 @@ void moduleFreeArgs(struct redisCommandArg *args, int num_args) {
zfree((char *)args[j].summary);
zfree((char *)args[j].since);
zfree((char *)args[j].deprecated_since);
zfree((char *)args[j].display_text);
 
if (args[j].subargs) {
moduleFreeArgs(args[j].subargs, args[j].num_args);
......
......@@ -326,6 +326,7 @@ typedef struct RedisModuleCommandArg {
int flags; /* The REDISMODULE_CMD_ARG_* macros. */
const char *deprecated_since;
struct RedisModuleCommandArg *subargs;
const char *display_text;
} RedisModuleCommandArg;
typedef struct {
......
......@@ -4514,6 +4514,7 @@ void addReplyCommandArgList(client *c, struct redisCommandArg *args, int num_arg
addReplyArrayLen(c, num_args);
for (int j = 0; j<num_args; j++) {
/* Count our reply len so we don't have to use deferred reply. */
int has_display_text = 1;
long maplen = 2;
if (args[j].key_spec_index != -1) maplen++;
if (args[j].token) maplen++;
......@@ -4521,8 +4522,11 @@ void addReplyCommandArgList(client *c, struct redisCommandArg *args, int num_arg
if (args[j].since) maplen++;
if (args[j].deprecated_since) maplen++;
if (args[j].flags) maplen++;
if (args[j].type == ARG_TYPE_ONEOF || args[j].type == ARG_TYPE_BLOCK)
if (args[j].type == ARG_TYPE_ONEOF || args[j].type == ARG_TYPE_BLOCK) {
has_display_text = 0;
maplen++;
}
if (has_display_text) maplen++;
addReplyMapLen(c, maplen);
addReplyBulkCString(c, "name");
......@@ -4531,6 +4535,10 @@ void addReplyCommandArgList(client *c, struct redisCommandArg *args, int num_arg
addReplyBulkCString(c, "type");
addReplyBulkCString(c, ARG_TYPE_STR[args[j].type]);
if (has_display_text) {
addReplyBulkCString(c, "display_text");
addReplyBulkCString(c, args[j].display_text ? args[j].display_text : args[j].name);
}
if (args[j].key_spec_index != -1) {
addReplyBulkCString(c, "key_spec_index");
addReplyLongLong(c, args[j].key_spec_index);
......
......@@ -1985,7 +1985,7 @@ typedef struct {
* 2. keynum: there's an arg that contains the number of key args somewhere before the keys themselves
*/
/* Must be synced with generate-command-code.py */
/* WARNING! Must be synced with generate-command-code.py and RedisModuleKeySpecBeginSearchType */
typedef enum {
KSPEC_BS_INVALID = 0, /* Must be 0 */
KSPEC_BS_UNKNOWN,
......@@ -1993,7 +1993,7 @@ typedef enum {
KSPEC_BS_KEYWORD
} kspec_bs_type;
/* Must be synced with generate-command-code.py */
/* WARNING! Must be synced with generate-command-code.py and RedisModuleKeySpecFindKeysType */
typedef enum {
KSPEC_FK_INVALID = 0, /* Must be 0 */
KSPEC_FK_UNKNOWN,
......@@ -2001,6 +2001,7 @@ typedef enum {
KSPEC_FK_KEYNUM
} kspec_fk_type;
/* WARNING! This struct must match RedisModuleCommandKeySpec */
typedef struct {
/* Declarative data */
const char *notes;
......@@ -2068,6 +2069,7 @@ typedef enum {
#define CMD_ARG_MULTIPLE (1<<1)
#define CMD_ARG_MULTIPLE_TOKEN (1<<2)
/* WARNING! This struct must match RedisModuleCommandArg */
typedef struct redisCommandArg {
const char *name;
redisCommandArgType type;
......@@ -2078,6 +2080,7 @@ typedef struct redisCommandArg {
int flags;
const char *deprecated_since;
struct redisCommandArg *subargs;
const char *display_text;
/* runtime populated data */
int num_args;
} redisCommandArg;
......@@ -2107,6 +2110,7 @@ typedef enum {
RESP3_NULL,
} redisCommandRESP3Type;
/* WARNING! This struct must match RedisModuleCommandHistoryEntry */
typedef struct {
const char *since;
const char *changes;
......
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