I need to delete some keys in my redis cluster which can only be accessed from a jump machine deployed in the kubernetes cluster.
So if I know the key I can delete it by the following command without problem:
➜ kubectl exec -it jump-machine -- /usr/local/bin/redis-cli -c -h redis-cluster-host DEL "the-key"
(interger) 1
But if I want to do it in batch then it gives output 0 which means not deleted:
➜ kubectl exec -it jump-machine -- /usr/local/bin/redis-cli -c -h redis-cluster-host --scan --pattern "*the-key-pattern*" | xargs -L 1 kubectl exec -it jump-machine -- /usr/local/bin/redis-cli -c -h redis-cluster-host -c DEL
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
Unable to use a TTY - input is not a terminal or the right kind of file
0
I'm quite new about using the xargs
, and I can't tell where is wrong.
I tried debug it with the following command, it gives all the keys without issue:
➜ kubectl exec -it jump-machine -- /usr/local/bin/redis-cli -c -h redis-cluster-host --scan --pattern "*the-key-pattern*" | xargs -L 1 echo
the-key-pattern-1
the-key-pattern-2
the-key-pattern-3
...
Hope someone can shed some light on it, thanks in advance!
I think you should remove the kubectl
part after xargs
, like this:
kubectl exec -it jump-machine -- bash -c '/usr/local/bin/redis-cli -c -h redis-cluster-host --scan --pattern "*the-key-pattern*" | xargs -i /usr/local/bin/redis-cli -c -h redis-cluster-host DEL {}'
xargs -L 1
to xargs -i
, because xargs -L 1
is for running on mac osx, and now the single quoted makes xargs
be running on linux, so -L
is not recognized{}
is critical, otherwise you'll get (error) CROSSSLOT Keys in request don't hash to the same slot
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments