summaryrefslogtreecommitdiff
path: root/tests/integration
diff options
context:
space:
mode:
authorBinbin <binloveplay1314@qq.com>2021-12-30 18:10:04 +0800
committerGitHub <noreply@github.com>2021-12-30 12:10:04 +0200
commit4836ae32c7eb485dd4b0196ec67b9838c6d87f80 (patch)
treee6c7071f3816b26481a8376d7e654402871eafb7 /tests/integration
parent5006eab5527155413aa94ed7c7f6b93344f92cbe (diff)
downloadredis-4836ae32c7eb485dd4b0196ec67b9838c6d87f80.tar.gz
redis-cli: Add -X option and extend --cluster call take arg from stdin (#9980)
There are two changes in this commit: 1. Add -X option to redis-cli. Currently `-x` can only be used to provide the last argument, so you can do `redis-cli dump keyname > key.dump`, and then do `redis-cli -x restore keyname 0 < key.dump`. But what if you want to add the replace argument (which comes last?). oran suggested adding such usage: `redis-cli -X <tag> restore keyname <tag> replace < key.dump` i.e. you're able to provide a string in the arguments that's gonna be substituted with the content from stdin. Note that the tag name should not conflict with others non-replaced args. And the -x and -X options are conflicting. Some usages: ``` [root]# echo mypasswd | src/redis-cli -X passwd_tag mset username myname password passwd_tag OK [root]# echo username > username.txt [root]# head -c -1 username.txt | src/redis-cli -X name_tag mget name_tag password 1) "myname" 2) "mypasswd\n" ``` 2. Handle the combination of both `-x` and `--cluster` or `-X` and `--cluster` Extend the broadcast option to receive the last arg or <tag> arg from the stdin. Now we can use `redis-cli -x --cluster call <host>:<port> cmd`, or `redis-cli -X <tag> --cluster call <host>:<port> cmd <tag>`. (support part of #9899)
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/redis-cli.tcl48
1 files changed, 40 insertions, 8 deletions
diff --git a/tests/integration/redis-cli.tcl b/tests/integration/redis-cli.tcl
index 993841217..4b9ce38d1 100644
--- a/tests/integration/redis-cli.tcl
+++ b/tests/integration/redis-cli.tcl
@@ -108,12 +108,20 @@ start_server {tags {"cli"}} {
_run_cli [srv host] [srv port] $::dbnum {} {*}$args
}
- proc run_cli_with_input_pipe {cmd args} {
- _run_cli [srv host] [srv port] $::dbnum [list pipe $cmd] -x {*}$args
+ proc run_cli_with_input_pipe {mode cmd args} {
+ if {$mode == "x" } {
+ _run_cli [srv host] [srv port] $::dbnum [list pipe $cmd] -x {*}$args
+ } elseif {$mode == "X"} {
+ _run_cli [srv host] [srv port] $::dbnum [list pipe $cmd] -X tag {*}$args
+ }
}
- proc run_cli_with_input_file {path args} {
- _run_cli [srv host] [srv port] $::dbnum [list path $path] -x {*}$args
+ proc run_cli_with_input_file {mode path args} {
+ if {$mode == "x" } {
+ _run_cli [srv host] [srv port] $::dbnum [list path $path] -x {*}$args
+ } elseif {$mode == "X"} {
+ _run_cli [srv host] [srv port] $::dbnum [list path $path] -X tag {*}$args
+ }
}
proc run_cli_host_port_db {host port db args} {
@@ -201,14 +209,22 @@ start_server {tags {"cli"}} {
}
test_tty_cli "Read last argument from pipe" {
- assert_equal "OK" [run_cli_with_input_pipe "echo foo" set key]
+ assert_equal "OK" [run_cli_with_input_pipe x "echo foo" set key]
assert_equal "foo\n" [r get key]
+
+ assert_equal "OK" [run_cli_with_input_pipe X "echo foo" set key2 tag]
+ assert_equal "foo\n" [r get key2]
}
test_tty_cli "Read last argument from file" {
set tmpfile [write_tmpfile "from file"]
- assert_equal "OK" [run_cli_with_input_file $tmpfile set key]
+
+ assert_equal "OK" [run_cli_with_input_file x $tmpfile set key]
assert_equal "from file" [r get key]
+
+ assert_equal "OK" [run_cli_with_input_file X $tmpfile set key2 tag]
+ assert_equal "from file" [r get key2]
+
file delete $tmpfile
}
@@ -280,14 +296,22 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS
}
test_nontty_cli "Read last argument from pipe" {
- assert_equal "OK" [run_cli_with_input_pipe "echo foo" set key]
+ assert_equal "OK" [run_cli_with_input_pipe x "echo foo" set key]
assert_equal "foo\n" [r get key]
+
+ assert_equal "OK" [run_cli_with_input_pipe X "echo foo" set key2 tag]
+ assert_equal "foo\n" [r get key2]
}
test_nontty_cli "Read last argument from file" {
set tmpfile [write_tmpfile "from file"]
- assert_equal "OK" [run_cli_with_input_file $tmpfile set key]
+
+ assert_equal "OK" [run_cli_with_input_file x $tmpfile set key]
assert_equal "from file" [r get key]
+
+ assert_equal "OK" [run_cli_with_input_file X $tmpfile set key2 tag]
+ assert_equal "from file" [r get key2]
+
file delete $tmpfile
}
@@ -399,4 +423,12 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS
file delete $cmds
}
+
+ test "Options -X with illegal argument" {
+ assert_error "*-x and -X are mutually exclusive*" {run_cli -x -X tag}
+
+ assert_error "*Unrecognized option or bad number*" {run_cli -X}
+
+ assert_error "*tag not match*" {run_cli_with_input_pipe X "echo foo" set key wrong_tag}
+ }
}