0

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?

randombits
  • 47,058
  • 76
  • 251
  • 433

1 Answers1

7

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.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • If I do that, I get this output from xargs: xargs: unmatched double quote; by default quotes are special to xargs unless you use the -0 option – randombits Nov 28 '12 at 01:48
  • 1
    @randombits: Note, though, that [`del`](http://redis.io/commands/del) is variadic since 2.6 -- i.e., it takes an arbitrary number of arguments. So you could do something like `redis-cli del $(redis-cli keys "resque:lock:*")`. – Linus Thiel Nov 28 '12 at 11:30
  • I don't know if you could be interested but you may want to use Redsmin ( https://redsmin.com ) a GUI for Redis that supports batch operations (deletion/rename/...) on keys that match a pattern. – FGRibreau Nov 28 '12 at 19:11