Search code examples
redisredis-cli

How to delete Redis keys with special characters?


I cannot delete a key of the format ENV:NAMESPACE:?''?""-last from our Redis instance. It appears to have been added maliciously.

Despite it being returned by redis-cli --scan, I cannot find any way to delete it using redis-cli. Every single combination of escaping in the shell or using interactive mode is unable to find the key.

Just a few attempts include:

$ redis-cli --scan --pattern 'ENV:NAMESPACE:*-last' | xargs redis-cli del
xargs: unterminated quote
$ redis-cli del ENV:NAMESPACE:?''?""-last
(integer) 0
$ redis-cli del "ENV:NAMESPACE:?''?\"\"-last"
(integer) 0
$ redis-cli del 'ENV:NAMESPACE:?'"'"''"'"'?""-last'
$redis-cli
> del ENV:NAMESPACE:?''?""-last
Invalid argument(s)
> del "ENV:NAMESPACE:?''?\"\"-last"
(integer) 0
> del 'ENV:NAMESPACE:?\'\'?""-last'
(integer) 0

Anyone know a way to make this work or a reasonable alternative to delete the key?


Solution

  • I ended up trying the python client per ceejayoz's suggestion.

    Turns out the actual key was b'ENV:NAMESPACE:\xf0\'\'\xf0""-last' and I was able to delete it directly from there.