How to batch delete the redis keys from local machine and through a jump machine inside kubernetes cluster?

Jeff Tian

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!

gmelis

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 {}'

Notice

  1. the single quote is critical
  2. change the 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
  3. {} 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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

scp protected file from remote machine to local machine through terminal

From Dev

scp protected file from remote machine to local machine through terminal

From Dev

Access denied issue when tried to copy from remote machine to local through batch file

From Dev

how to delete local machine registry key?

From Dev

How to execute a shell script stored on remote machine from a local machine?

From Dev

How to copy a directory from local machine to remote machine

From Dev

How to copy a directory from local machine to remote machine

From Dev

How to copy files from a virtual machine to a local machine?

From Dev

How to copy files from local machine to remote virtual machine?

From Dev

How to copy (or move) files from remote machine to local machine?

From Dev

How do I SCP from remote machine to local machine?

From Dev

redis cluster: delete keys from smembers in lua script

From Dev

Batch file to copy from remote desktop to local machine

From Dev

how to delete nodes from redis cluster?

From Dev

copying file from a pod to local machine directly from inside the pod

From Dev

How to transfer file from local disk to Cloudera Virtual Machine? (I've looked through SO and found nothing)

From Dev

Redis Cluster: how to delete all keys for a specific hashtag

From Dev

How to host a website from my local machine?

From Dev

How to host a website from my local machine?

From Dev

Does a request from the local machine go through the load balancer?

From Dev

Delete key from registry HKEY_LOCAL_MACHINE

From Dev

Delete key from registry HKEY_LOCAL_MACHINE

From Dev

How can I reach a single local machine through OpenVPN?

From Dev

Unkown command `J` while ssh to Ubuntu machine from windows through jump host

From Dev

Executing a batch file in a remote machine through PsExec

From Dev

Can I safely delete "...\AppData\Local\Redis" folder on my Windows machine?

From Dev

How to access hadoop cluster (unix) from client windows machine

From Dev

How to remove virtual machine from Hyper-V cluster?

From Dev

Keeping GPG Private Keys on Local machine?

Related Related

  1. 1

    scp protected file from remote machine to local machine through terminal

  2. 2

    scp protected file from remote machine to local machine through terminal

  3. 3

    Access denied issue when tried to copy from remote machine to local through batch file

  4. 4

    how to delete local machine registry key?

  5. 5

    How to execute a shell script stored on remote machine from a local machine?

  6. 6

    How to copy a directory from local machine to remote machine

  7. 7

    How to copy a directory from local machine to remote machine

  8. 8

    How to copy files from a virtual machine to a local machine?

  9. 9

    How to copy files from local machine to remote virtual machine?

  10. 10

    How to copy (or move) files from remote machine to local machine?

  11. 11

    How do I SCP from remote machine to local machine?

  12. 12

    redis cluster: delete keys from smembers in lua script

  13. 13

    Batch file to copy from remote desktop to local machine

  14. 14

    how to delete nodes from redis cluster?

  15. 15

    copying file from a pod to local machine directly from inside the pod

  16. 16

    How to transfer file from local disk to Cloudera Virtual Machine? (I've looked through SO and found nothing)

  17. 17

    Redis Cluster: how to delete all keys for a specific hashtag

  18. 18

    How to host a website from my local machine?

  19. 19

    How to host a website from my local machine?

  20. 20

    Does a request from the local machine go through the load balancer?

  21. 21

    Delete key from registry HKEY_LOCAL_MACHINE

  22. 22

    Delete key from registry HKEY_LOCAL_MACHINE

  23. 23

    How can I reach a single local machine through OpenVPN?

  24. 24

    Unkown command `J` while ssh to Ubuntu machine from windows through jump host

  25. 25

    Executing a batch file in a remote machine through PsExec

  26. 26

    Can I safely delete "...\AppData\Local\Redis" folder on my Windows machine?

  27. 27

    How to access hadoop cluster (unix) from client windows machine

  28. 28

    How to remove virtual machine from Hyper-V cluster?

  29. 29

    Keeping GPG Private Keys on Local machine?

HotTag

Archive