如何删除钥匙? [英] How do I remove keys?

查看:90
本文介绍了如何删除钥匙?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要删除与"user *"匹配的键.

I want to remove keys that match "user*".

我如何在Redis命令行中做到这一点?

How do I do that in redis command line?

推荐答案

此功能目前无法一次性完成(请参见

This is not a feature right now to be able to do in one shot (see the comments in the DEL documentation). Unfortunately, you are only left with using KEYS, looping through the results, and then using DEL to remove each one.

稍微使用bash会如何?

How about using bash a bit to help?

for key in `echo 'KEYS user*' | redis-cli | awk '{print $1}'`
 do echo DEL $key
done | redis-cli

要逐步进行:

  1. echo'KEYS user *'|redis-cli |awk'{print $ 1}'-使用awk获取所有键并删除不需要的文本.
  2. echo DEL $ key -为每一个创建一个echo语句以将其删除.
  3. |redis-cli -使用DEL语句,然后将它们传递回cli.
  1. echo 'KEYS user*' | redis-cli | awk '{print $1}' -- get all the keys and strip out the extra text you don't want with awk.
  2. echo DEL $key -- for each one, create an echo statement to remove it.
  3. | redis-cli -- take the DEL statements and pass them back into the cli.

不建议这是最好的方法(如果某些用户名中包含空格,则可能会出现问题,但希望您能理解这一点).

Not suggesting this is the best approach (you might have some issues if some of your usernames have spaces in them, but hopefully you get the point).

这篇关于如何删除钥匙?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆