在redis中,我如何删除密钥? [英] In redis, how do i remove keys?

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

问题描述

我要删除与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. |

  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).

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

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