Search code examples
redisazure-redis-cacheredis-cli

Redis Pattern delete is not working on Ubuntu bash for Windows


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?


Solution

  • 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.