Support connection schemes valkey:// and valkeys:// (#199)
1. Support valkey:// and valkeys:// scheme in valkey-cli and valkey-benchmark. Retain the original Redis schemes for compatibility. 2. Add unit tests for valid URI, all schemes. Fixes: https://github.com/valkey-io/valkey/issues/198 Fixes: https://github.com/valkey-io/valkey/issues/200 --------- Signed-off-by: Lipeng Zhu <lipeng.zhu@intel.com>
This commit is contained in:
parent
a989ee5c05
commit
87a5bfc002
@ -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: [[<username> ":"] <password> "@"] [<hostname> [":" <port>]]
|
||||
* path: ["/" [<db>]]
|
||||
*
|
||||
@ -318,8 +318,11 @@ 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://";
|
||||
/* 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,"rediss:// 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);
|
||||
|
@ -1592,10 +1592,10 @@ usage:
|
||||
" -s <socket> Server socket (overrides host and port)\n"
|
||||
" -a <password> Password for Valkey Auth\n"
|
||||
" --user <username> Used to send ACL style 'AUTH username pass'. Needs -a.\n"
|
||||
" -u <uri> Server URI on format redis://user:password@host:port/dbnum\n"
|
||||
" -u <uri> 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 <clients> 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"
|
||||
|
@ -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 " CLI_AUTH_ENV "\n"
|
||||
" environment variable will be ignored.\n"
|
||||
" -u <uri> Server URI on format redis://user:password@host:port/dbnum\n"
|
||||
" -u <uri> 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 <repeat> Execute specified command N times.\n"
|
||||
" -i <interval> When -r is used, waits <interval> 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"
|
||||
|
@ -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]]
|
||||
assert_equal {PONG} [exec {*}$cmdline PING]
|
||||
}
|
||||
|
||||
test "Valid Connection Scheme: valkey://" {
|
||||
set cmdline [valkeycliuri "valkey://" [srv host] [srv port]]
|
||||
assert_equal {PONG} [exec {*}$cmdline PING]
|
||||
}
|
||||
|
||||
if {$::tls} {
|
||||
test "Valid Connection Scheme: rediss://" {
|
||||
set cmdline [valkeycliuri "rediss://" [srv host] [srv port]]
|
||||
assert_equal {PONG} [exec {*}$cmdline PING]
|
||||
}
|
||||
|
||||
test "Valid Connection Scheme: valkeys://" {
|
||||
set cmdline [valkeycliuri "valkeys://" [srv host] [srv port]]
|
||||
assert_equal {PONG} [exec {*}$cmdline PING]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -19,6 +19,13 @@ proc valkeycli {host port {opts {}}} {
|
||||
return $cmd
|
||||
}
|
||||
|
||||
proc valkeycliuri {scheme host port {opts {}}} {
|
||||
set cmd [list src/valkey-cli -u $scheme$host:$port]
|
||||
lappend cmd {*}[valkeycli_tls_config "tests"]
|
||||
lappend cmd {*}$opts
|
||||
return $cmd
|
||||
}
|
||||
|
||||
# Returns command line for executing valkey-cli with a unix socket address
|
||||
proc valkeycli_unixsocket {unixsocket {opts {}}} {
|
||||
return [list src/valkey-cli -s $unixsocket {*}$opts]
|
||||
|
Loading…
x
Reference in New Issue
Block a user