在看《redis入门指南》这篇文章中,第三章第二节介绍删除键的时候,有这样一段描述:
DEL命令的参数不支持通配符,但我们可以结合Linux的管道和xargs命令自己实现删除所有符合规则的键。比如要删除所有以“user:”开头的键,就可以执行redis-cli
KEYS "user:" | xargs redis-cli
DEL。另外,由于DEL命令支持多个键作为参数,所以还可以执行redis-cli DEL 'redis-cli KEYS
"user:"'来达到同样的效果,性能更好。
但是我测试的时候,第一个结合管道的命令能起作用,但是第二个貌似不起作用。
刚学习redis,请大神指教。
You read it wrong.
` and ' are two different things.
What they wrote is
Pay attention to the difference.
Single quotes directly treat the content within the single quotes as a string,
in redis,redis-cli DEL 'redis-cli KEYS "user:"'
redis-cli DEL 'redis-cli KEYS "user:"'
就是删除redis中名叫
redis-cli KEYS "user:"
is to delete the key namedredis-cli KEYS "user:"
The first thing to execute is , and the result is taken out (for example:)