randombits
randombits

Reputation: 48450

Deleting a lot of keys in Redis

Trying to do something like:

# redis-cli keys "resque:lock:*" |xargs -0 redis-cli del
xargs: argument line too long

What's the best way to work around this?

Upvotes: 0

Views: 2105

Answers (1)

John Kugelman
John Kugelman

Reputation: 361585

Get rid of the -0. I'm not familiar with redis, but from what I can tell redis-cli keys doesn't use a NUL separator.

The reason it barfs without it is because of the way it handles quotes. From man xargs:

xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (default is /bin/echo) one or more times with any initial-arguments followed by items read from standard input. Blank lines on the standard input are ignored.

Try xargs -d '\n'. That'll disable xarg's "smart" quote-handling and tell it to just read arguments line by line.

Upvotes: 7

Related Questions