0

I want to delete 137K keys by pattern match from Azure Cache for Redis.
I am using Ubuntu bash for Windows.

Commands I tried:

redis-cli -h HOST -p PORT -a PASSWORD keys 'customer*' | xargs redis-cli DEL
redis-cli -h HOST -p PORT -a PASSWORD --scan --pattern 'customer*' | xargs redis-cli DEL
  

Both does not delete any keys and only gives output:

(integer) 0

Screenshot of the output:

enter image description here

what am I missing here?

James Z
  • 12,209
  • 10
  • 24
  • 44
Manish Gupta
  • 1,405
  • 14
  • 32
  • Can you save the result `redis-cli -h HOST -p PORT -a PASSWORD keys 'customer*'` to a file and check if there is any problem (may be line break issue). – samabcde Dec 11 '21 at 14:23
  • 1
    It worked fine when I added host port and password in xargs as mentioned by @Mahdi in below answer. – Manish Gupta Dec 14 '21 at 15:00

1 Answers1

3

You should pass host and port to second command too. like this:

redis-cli -h HOST -p PORT -a PASSWORD keys 'customer*' | xargs redis-cli -h HOST -p PORT -a PASSWORD DEL

if you don't do this it just performs the command on redis that is hosted on localhost and default port 6379 without authentication. And apparently there is no redis or keys with this specification, that's why you got zero code as result.

Mahdi Yusefi
  • 441
  • 4
  • 13