From df1890ef7fc0691c0b940f00ddff14a1c395a52a Mon Sep 17 00:00:00 2001 From: Wen Hui Date: Wed, 17 May 2023 03:26:02 -0400 Subject: Allow SENTINEL CONFIG SET and SENTINEL CONFIG GET to handle multiple parameters. (#10362) Extend SENTINEL CONFIG SET and SENTINEL CONFIG GET to be compatible with variadic CONFIG SET and CONFIG GET and allow multiple parameters to be modified in a single call atomically. Co-authored-by: Oran Agra --- src/commands/sentinel-config.json | 14 +- src/sentinel.c | 262 ++++++++++++++-------- tests/sentinel/tests/15-config-set-config-get.tcl | 58 +++++ 3 files changed, 239 insertions(+), 95 deletions(-) create mode 100644 tests/sentinel/tests/15-config-set-config-get.tcl diff --git a/src/commands/sentinel-config.json b/src/commands/sentinel-config.json index ecc317603..6e3075f7c 100644 --- a/src/commands/sentinel-config.json +++ b/src/commands/sentinel-config.json @@ -1,12 +1,18 @@ { "CONFIG": { "summary": "Configures Redis Sentinel.", - "complexity": "O(1)", + "complexity": "O(N) when N is the number of configuration parameters provided", "group": "sentinel", "since": "6.2.0", "arity": -4, "container": "SENTINEL", "function": "sentinelCommand", + "history": [ + [ + "7.2.0", + "Added the ability to set and get multiple parameters in one call." + ] + ], "command_flags": [ "ADMIN", "SENTINEL", @@ -42,7 +48,7 @@ "type": "string" }, "announce-port": { - "type": "integer" + "type": "string" }, "sentinel-user": { "type": "string" @@ -87,6 +93,7 @@ "name":"set", "token":"SET", "type":"block", + "multiple": true, "arguments":[ { "name":"parameter", @@ -101,7 +108,8 @@ { "token":"GET", "name":"parameter", - "type":"string" + "type":"string", + "multiple": true } ] } diff --git a/src/sentinel.c b/src/sentinel.c index 326def135..6a1cd1777 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -3178,6 +3178,13 @@ void sentinelSendPeriodicCommands(sentinelRedisInstance *ri) { } /* =========================== SENTINEL command ============================= */ +static void populateDict(dict *options_dict, char **options) { + for (int i=0; options[i]; i++) { + sds option = sdsnew(options[i]); + if (dictAdd(options_dict, option, NULL)==DICT_ERR) + sdsfree(option); + } +} const char* getLogLevel(void) { switch (server.verbosity) { @@ -3189,52 +3196,112 @@ const char* getLogLevel(void) { return "unknown"; } -/* SENTINEL CONFIG SET