#StackBounty: #linux #command-line #bash #terminal #xargs How to batch delete the redis keys from local mache and through a jump machin…

Bounty: 50

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!


Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.