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