From 244df8ea54d2275ed9cc78d6ce104f42cbda19f5 Mon Sep 17 00:00:00 2001 From: Lipeng Zhu Date: Thu, 4 Apr 2024 06:54:46 -0400 Subject: [PATCH 1/4] Rename connection scheme from redis:// to valkey://. Signed-off-by: Lipeng Zhu --- src/cli_common.c | 8 ++++---- src/valkey-benchmark.c | 4 ++-- src/valkey-cli.c | 6 +++--- tests/support/benchmark.tcl | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cli_common.c b/src/cli_common.c index c55933418d..78d8f85d71 100644 --- a/src/cli_common.c +++ b/src/cli_common.c @@ -306,7 +306,7 @@ static sds percentDecode(const char *pe, size_t len) { /* Parse a URI and extract the server connection information. * URI scheme is based on the provisional specification[1] excluding support * for query parameters. Valid URIs are: - * scheme: "redis://" + * scheme: "valkey://" * authority: [[ ":"] "@"] [ [":" ]] * path: ["/" []] * @@ -318,8 +318,8 @@ void parseRedisUri(const char *uri, const char* tool_name, cliConnInfo *connInfo UNUSED(tls_flag); #endif - const char *scheme = "redis://"; - const char *tlsscheme = "rediss://"; + const char *scheme = "valkey://"; + const char *tlsscheme = "valkeys://"; const char *curr = uri; const char *end = uri + strlen(uri); const char *userinfo, *username, *port, *host, *path; @@ -330,7 +330,7 @@ void parseRedisUri(const char *uri, const char* tool_name, cliConnInfo *connInfo *tls_flag = 1; curr += strlen(tlsscheme); #else - fprintf(stderr,"rediss:// is only supported when %s is compiled with OpenSSL\n", tool_name); + fprintf(stderr,"valkeys:// is only supported when %s is compiled with OpenSSL\n", tool_name); exit(1); #endif } else if (!strncasecmp(scheme, curr, strlen(scheme))) { diff --git a/src/valkey-benchmark.c b/src/valkey-benchmark.c index b099751233..ad766adbf8 100644 --- a/src/valkey-benchmark.c +++ b/src/valkey-benchmark.c @@ -1592,10 +1592,10 @@ int parseOptions(int argc, char **argv) { " -s Server socket (overrides host and port)\n" " -a Password for Valkey Auth\n" " --user Used to send ACL style 'AUTH username pass'. Needs -a.\n" -" -u Server URI on format redis://user:password@host:port/dbnum\n" +" -u Server URI on format valkey://user:password@host:port/dbnum\n" " User, password and dbnum are optional. For authentication\n" " without a username, use username 'default'. For TLS, use\n" -" the scheme 'rediss'.\n" +" the scheme 'valkeys'.\n" " -c Number of parallel connections (default 50).\n" " Note: If --cluster is used then number of clients has to be\n" " the same or higher than the number of nodes.\n" diff --git a/src/valkey-cli.c b/src/valkey-cli.c index ba16d03fa7..40791b6e11 100644 --- a/src/valkey-cli.c +++ b/src/valkey-cli.c @@ -3040,10 +3040,10 @@ static void usage(int err) { " --askpass Force user to input password with mask from STDIN.\n" " If this argument is used, '-a' and " REDIS_CLI_AUTH_ENV "\n" " environment variable will be ignored.\n" -" -u Server URI on format redis://user:password@host:port/dbnum\n" +" -u Server URI on format valkey://user:password@host:port/dbnum\n" " User, password and dbnum are optional. For authentication\n" " without a username, use username 'default'. For TLS, use\n" -" the scheme 'rediss'.\n" +" the scheme 'valkeys'.\n" " -r Execute specified command N times.\n" " -i When -r is used, waits seconds per command.\n" " It is possible to specify sub-second times like -i 0.1.\n" @@ -3130,7 +3130,7 @@ version,tls_usage); " Use --cluster help to list all available cluster manager commands.\n" "\n" "Examples:\n" -" valkey-cli -u redis://default:PASSWORD@localhost:6379/0\n" +" valkey-cli -u valkey://default:PASSWORD@localhost:6379/0\n" " cat /etc/passwd | valkey-cli -x set mypasswd\n" " valkey-cli -D \"\" --raw dump key > key.dump && valkey-cli -X dump_tag restore key2 0 dump_tag replace < key.dump\n" " valkey-cli -r 100 lpush mylist x\n" diff --git a/tests/support/benchmark.tcl b/tests/support/benchmark.tcl index 35a8d26232..eedcfa5ce6 100644 --- a/tests/support/benchmark.tcl +++ b/tests/support/benchmark.tcl @@ -19,14 +19,14 @@ proc redisbenchmark {host port {opts {}}} { } proc redisbenchmarkuri {host port {opts {}}} { - set cmd [list src/valkey-benchmark -u redis://$host:$port] + set cmd [list src/valkey-benchmark -u valkey://$host:$port] lappend cmd {*}[redisbenchmark_tls_config "tests"] lappend cmd {*}$opts return $cmd } proc redisbenchmarkuriuserpass {host port user pass {opts {}}} { - set cmd [list src/valkey-benchmark -u redis://$user:$pass@$host:$port] + set cmd [list src/valkey-benchmark -u valkey://$user:$pass@$host:$port] lappend cmd {*}[redisbenchmark_tls_config "tests"] lappend cmd {*}$opts return $cmd From 63a27aab246712133747cef372569178ba6e6e1f Mon Sep 17 00:00:00 2001 From: Lipeng Zhu Date: Thu, 4 Apr 2024 08:44:02 -0400 Subject: [PATCH 2/4] Support redis:// and rediss:// scheme for compatibility. Signed-off-by: Lipeng Zhu --- src/cli_common.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cli_common.c b/src/cli_common.c index 78d8f85d71..86fdf10cbc 100644 --- a/src/cli_common.c +++ b/src/cli_common.c @@ -320,6 +320,9 @@ void parseRedisUri(const char *uri, const char* tool_name, cliConnInfo *connInfo const char *scheme = "valkey://"; const char *tlsscheme = "valkeys://"; + /* We need to support redis:// and rediss:// too for compatibility. */ + const char *redisScheme = "redis://"; + const char *redisTlsscheme = "rediss://"; const char *curr = uri; const char *end = uri + strlen(uri); const char *userinfo, *username, *port, *host, *path; @@ -330,11 +333,21 @@ void parseRedisUri(const char *uri, const char* tool_name, cliConnInfo *connInfo *tls_flag = 1; curr += strlen(tlsscheme); #else - fprintf(stderr,"valkeys:// is only supported when %s is compiled with OpenSSL\n", tool_name); + fprintf(stderr,"valkeys:// and rediss:// are only supported when %s is compiled with OpenSSL\n", tool_name); + exit(1); +#endif + } else if (!strncasecmp(redisTlsscheme, curr, strlen(redisTlsscheme))) { +#ifdef USE_OPENSSL + *tls_flag = 1; + curr += strlen(redisTlsscheme); +#else + fprintf(stderr,"valkeys:// and rediss:// are only supported when %s is compiled with OpenSSL\n", tool_name); exit(1); #endif } else if (!strncasecmp(scheme, curr, strlen(scheme))) { curr += strlen(scheme); + } else if (!strncasecmp(redisScheme, curr, strlen(redisScheme))) { + curr += strlen(redisScheme); } else { fprintf(stderr,"Invalid URI scheme\n"); exit(1); From 0864507afe80d6a468b6c09494b8a09ddd91519c Mon Sep 17 00:00:00 2001 From: Lipeng Zhu Date: Thu, 4 Apr 2024 08:55:40 -0400 Subject: [PATCH 3/4] Add unit tests for valid connection scheme. Signed-off-by: Lipeng Zhu --- tests/integration/redis-cli.tcl | 22 ++++++++++++++++++++++ tests/support/cli.tcl | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/tests/integration/redis-cli.tcl b/tests/integration/redis-cli.tcl index da82dda652..2883433955 100644 --- a/tests/integration/redis-cli.tcl +++ b/tests/integration/redis-cli.tcl @@ -606,4 +606,26 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS assert_equal 3 [exec {*}$cmdline ZCARD new_zset] assert_equal "a\n1\nb\n2\nc\n3" [exec {*}$cmdline ZRANGE new_zset 0 -1 WITHSCORES] } + + test "Valid Connection Scheme: redis://" { + set cmdline [valkeycliuri "redis://" [srv host] [srv port]] + exec {*}$cmdline PING + } + + test "Valid Connection Scheme: valkey://" { + set cmdline [valkeycliuri "valkey://" [srv host] [srv port]] + exec {*}$cmdline PING + } + + if {$::tls} { + test "Valid Connection Scheme: redis://" { + set cmdline [valkeycliuri "rediss://" [srv host] [srv port]] + exec {*}$cmdline PING + } + + test "Valid Connection Scheme: valkeys://" { + set cmdline [valkeycliuri "valkeys://" [srv host] [srv port]] + exec {*}$cmdline PING + } + } } diff --git a/tests/support/cli.tcl b/tests/support/cli.tcl index 4bd693369b..52dc2c5484 100644 --- a/tests/support/cli.tcl +++ b/tests/support/cli.tcl @@ -19,6 +19,13 @@ proc rediscli {host port {opts {}}} { return $cmd } +proc valkeycliuri {scheme host port {opts {}}} { + set cmd [list src/valkey-cli -u $scheme$host:$port] + lappend cmd {*}[rediscli_tls_config "tests"] + lappend cmd {*}$opts + return $cmd +} + # Returns command line for executing redis-cli with a unix socket address proc rediscli_unixsocket {unixsocket {opts {}}} { return [list src/valkey-cli -s $unixsocket {*}$opts] From d789b5b5df67cbe56858c9fae936e58d8f94cd04 Mon Sep 17 00:00:00 2001 From: Lipeng Zhu Date: Thu, 4 Apr 2024 09:29:07 -0400 Subject: [PATCH 4/4] Fix typo. Signed-off-by: Lipeng Zhu --- tests/integration/redis-cli.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/redis-cli.tcl b/tests/integration/redis-cli.tcl index 2883433955..f8ff5dd33a 100644 --- a/tests/integration/redis-cli.tcl +++ b/tests/integration/redis-cli.tcl @@ -618,7 +618,7 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS } if {$::tls} { - test "Valid Connection Scheme: redis://" { + test "Valid Connection Scheme: rediss://" { set cmdline [valkeycliuri "rediss://" [srv host] [srv port]] exec {*}$cmdline PING }