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

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

问题描述

我想删除匹配user*"的键.

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

如何在 redis 命令行中执行此操作?

How do I do that in redis command line?

推荐答案

这不是现在可以一次性完成的功能(请参阅 DEL 文档).不幸的是,您只能使用 KEYS,循环遍历结果,然后使用 DEL 删除每一个.

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天全站免登陆