COMMAND: Use underscores instead of hyphens in attributes (#9959)

some languages can build a json-like object by parsing a textual json,
but it works poorly when attributes contain hyphens

example in JS:
```
let j = JSON.parse(json)
j['key-name'] <- works
j.key-name <= illegal syntax
```
This commit is contained in:
guybe7 2021-12-18 08:00:42 +01:00 committed by GitHub
parent 792afb4432
commit 5df070ba39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 20 deletions

View File

@ -3795,7 +3795,7 @@ void addReplyCommandArgList(client *c, struct redisCommandArg *args) {
addReplyBulkCString(c, ARG_TYPE_STR[args[j].type]);
maplen++;
if (args[j].type == ARG_TYPE_KEY) {
addReplyBulkCString(c, "key-spec-index");
addReplyBulkCString(c, "key_spec_index");
addReplyLongLong(c, args[j].key_spec_index);
maplen++;
}
@ -3884,7 +3884,7 @@ void addReplyCommandKeySpecs(client *c, struct redisCommand *cmd) {
addReplyBulkCString(c, "flags");
addReplyFlagsForKeyArgs(c,cmd->key_specs[i].flags);
addReplyBulkCString(c, "begin-search");
addReplyBulkCString(c, "begin_search");
switch (cmd->key_specs[i].begin_search_type) {
case KSPEC_BS_UNKNOWN:
addReplyMapLen(c, 2);
@ -3917,10 +3917,10 @@ void addReplyCommandKeySpecs(client *c, struct redisCommand *cmd) {
addReplyLongLong(c, cmd->key_specs[i].bs.keyword.startfrom);
break;
default:
serverPanic("Invalid begin-search key spec type %d", cmd->key_specs[i].begin_search_type);
serverPanic("Invalid begin_search key spec type %d", cmd->key_specs[i].begin_search_type);
}
addReplyBulkCString(c, "find-keys");
addReplyBulkCString(c, "find_keys");
switch (cmd->key_specs[i].find_keys_type) {
case KSPEC_FK_UNKNOWN:
addReplyMapLen(c, 2);
@ -3959,7 +3959,7 @@ void addReplyCommandKeySpecs(client *c, struct redisCommand *cmd) {
addReplyLongLong(c, cmd->key_specs[i].fk.keynum.keystep);
break;
default:
serverPanic("Invalid find-keys key spec type %d", cmd->key_specs[i].begin_search_type);
serverPanic("Invalid find_keys key spec type %d", cmd->key_specs[i].begin_search_type);
}
}
}
@ -4044,17 +4044,17 @@ void addReplyCommand(client *c, struct redisCommand *cmd) {
maplen++;
}
if (cmd->doc_flags) {
addReplyBulkCString(c, "doc-flags");
addReplyBulkCString(c, "doc_flags");
addReplyDocFlagsForCommand(c, cmd);
maplen++;
}
if (cmd->deprecated_since) {
addReplyBulkCString(c, "deprecated-since");
addReplyBulkCString(c, "deprecated_since");
addReplyBulkCString(c, cmd->deprecated_since);
maplen++;
}
if (cmd->replaced_by) {
addReplyBulkCString(c, "replaced-by");
addReplyBulkCString(c, "replaced_by");
addReplyBulkCString(c, cmd->replaced_by);
maplen++;
}

View File

@ -16,8 +16,8 @@ start_server {tags {"modules"}} {
}
# Verify key-specs
set keyspecs [dict get $mydict key-specs]
assert_equal [lindex $keyspecs 0] {flags read begin-search {type index spec {index 1}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 1] {flags write begin-search {type index spec {index 2}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 0] {flags read begin_search {type index spec {index 1}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 1] {flags write begin_search {type index spec {index 2}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
}
test "Module key specs: Complex specs, case 1" {
@ -33,9 +33,9 @@ start_server {tags {"modules"}} {
}
# Verify key-specs
set keyspecs [dict get $mydict key-specs]
assert_equal [lindex $keyspecs 0] {flags {} begin-search {type index spec {index 1}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 1] {flags write begin-search {type keyword spec {keyword STORE startfrom 2}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 2] {flags read begin-search {type keyword spec {keyword KEYS startfrom 2}} find-keys {type keynum spec {keynumidx 0 firstkey 1 keystep 1}}}
assert_equal [lindex $keyspecs 0] {flags {} begin_search {type index spec {index 1}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 1] {flags write begin_search {type keyword spec {keyword STORE startfrom 2}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 2] {flags read begin_search {type keyword spec {keyword KEYS startfrom 2}} find_keys {type keynum spec {keynumidx 0 firstkey 1 keystep 1}}}
}
test "Module key specs: Complex specs, case 2" {
@ -51,11 +51,11 @@ start_server {tags {"modules"}} {
}
# Verify key-specs
set keyspecs [dict get $mydict key-specs]
assert_equal [lindex $keyspecs 0] {flags write begin-search {type keyword spec {keyword STORE startfrom 5}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 1] {flags read begin-search {type index spec {index 1}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 2] {flags read begin-search {type index spec {index 2}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 3] {flags write begin-search {type index spec {index 3}} find-keys {type keynum spec {keynumidx 0 firstkey 1 keystep 1}}}
assert_equal [lindex $keyspecs 4] {flags write begin-search {type keyword spec {keyword MOREKEYS startfrom 5}} find-keys {type range spec {lastkey -1 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 0] {flags write begin_search {type keyword spec {keyword STORE startfrom 5}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 1] {flags read begin_search {type index spec {index 1}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 2] {flags read begin_search {type index spec {index 2}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}
assert_equal [lindex $keyspecs 3] {flags write begin_search {type index spec {index 3}} find_keys {type keynum spec {keynumidx 0 firstkey 1 keystep 1}}}
assert_equal [lindex $keyspecs 4] {flags write begin_search {type keyword spec {keyword MOREKEYS startfrom 5}} find_keys {type range spec {lastkey -1 keystep 1 limit 0}}}
}
test "Module command list filtering" {

View File

@ -12,8 +12,8 @@ start_server {tags {"modules"}} {
dict append mydict $k $v
}
set subcmds [lsort [dict get $mydict subcommands]]
assert_equal [lindex $subcmds 0] {get -2 module 1 1 1 {} {summary {} since {} group module key-specs {{flags read begin-search {type index spec {index 1}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}}}}
assert_equal [lindex $subcmds 1] {set -2 module 1 1 1 {} {summary {} since {} group module key-specs {{flags write begin-search {type index spec {index 1}} find-keys {type range spec {lastkey 0 keystep 1 limit 0}}}}}}
assert_equal [lindex $subcmds 0] {get -2 module 1 1 1 {} {summary {} since {} group module key-specs {{flags read begin_search {type index spec {index 1}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}}}}
assert_equal [lindex $subcmds 1] {set -2 module 1 1 1 {} {summary {} since {} group module key-specs {{flags write begin_search {type index spec {index 1}} find_keys {type range spec {lastkey 0 keystep 1 limit 0}}}}}}
}
test "Module pure-container command fails on arity error" {