0

In my MacOs 10.15 environment I have a strange Redis behaviour when I list some keys with:

redis-cli -n 1 --scan --pattern "product_doctrine*"

It gives me for example:

product_doctrine[AppBundle\Entity\ColumnMapping\$GEDMO_TIMESTAMPABLE_CLASSMETADATA][21546]

But It doesn’t delete it using xargs:

redis-cli -n 1 --scan --pattern "product_doctrine*" | xargs -L 1 redis-cli -n 1 del
(integer) 0

Is it maybe of the key name having special characters? Because if I run this inide the redis-cli:

SCAN 0 MATCH product_doctrine*

it shows the keys with escaped antislash:

"product_doctrine[AppBundle\\Entity\\ShopSettings\\$GEDMO_SOFTDELETEABLE_CLASSMETADATA][11677]"

Inside redis-cli I can delete those kind of keys successfully with

127.0.0.1:6379[1]> del "product_doctrine[AppBundle\\Entity\\ShopSettings\\$GEDMO_SOFTDELETEABLE_CLASSMETADATA][11677]"
(integer) 1
numediaweb
  • 16,362
  • 12
  • 74
  • 110
  • Which OS are you on? Specifically, which `xargs`? Note that per its man page, `xargs` treats backslashes differently. This, combined with the shell's and redis-cli's quirks leads to your experience. – Itamar Haber Oct 16 '19 at 14:56
  • I run it on a MacOs 10.15 environment – numediaweb Oct 16 '19 at 15:12

1 Answers1

0

On macOS 10.14 the following does it:

redis-cli --scan --pattern "foo*" | sed 's/\\/\\\\/' | xargs -L 1 redis-cli DEL

¯\_(ツ)_/¯

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117