P.K.Hindustani
P.K.Hindustani

Reputation: 148

Getting Error to delete keys by pattern in redis

I am trying to execute query redis-cli --raw keys "$xx" | xargs redis-cli del but getting error.

ERR wrong number of arguments for 'del' command

Upvotes: 2

Views: 7847

Answers (2)

d-_-b
d-_-b

Reputation: 23161

Try this instead, to wrap the key in quotes:

redis-cli keys "pattern" | xargs -I% redis-cli del "%"

This takes each key as a variable, %, and passes it to redis-cli del but wraps it in double quotes in case it contains non-alphanumeric characters (like period,colon,etc.)

Upvotes: 4

klhr
klhr

Reputation: 3380

Check what redis-cli --raw keys "$xx" is returning: you'll see that error when you call redis-cli del without any arguments.

Upvotes: 1

Related Questions