From 5df070ba391c8870894a11e31f0c8fe2be9f8052 Mon Sep 17 00:00:00 2001 From: guybe7 Date: Sat, 18 Dec 2021 08:00:42 +0100 Subject: [PATCH] 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 ``` --- src/server.c | 16 ++++++++-------- tests/unit/moduleapi/keyspecs.tcl | 20 ++++++++++---------- tests/unit/moduleapi/subcommands.tcl | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/server.c b/src/server.c index e09974e41..8be093cc2 100644 --- a/src/server.c +++ b/src/server.c @@ -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++; } diff --git a/tests/unit/moduleapi/keyspecs.tcl b/tests/unit/moduleapi/keyspecs.tcl index f3e686f26..265b9e9ee 100644 --- a/tests/unit/moduleapi/keyspecs.tcl +++ b/tests/unit/moduleapi/keyspecs.tcl @@ -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" { diff --git a/tests/unit/moduleapi/subcommands.tcl b/tests/unit/moduleapi/subcommands.tcl index 5ae36f68f..9be6f5cea 100644 --- a/tests/unit/moduleapi/subcommands.tcl +++ b/tests/unit/moduleapi/subcommands.tcl @@ -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" {