删除基于图案的多个redis键
我正在尝试根据指定的密钥模式从REDIS实例中删除多个键。但是,我所看到的许多其他答案都独有的是,我需要在Redis控制台内完全执行此操作,而不会使用任何其他脚本或bash。原因是我需要从Redis门户的Azure Cache的控制台功能内执行此操作。我能够选择要使用扫描0 Match *mypattern *
的键,但是,我不知道将其“将”此操作到del
命令中。
I am trying to remove multiple keys from a Redis instance based on a specified key pattern. However, unique to many of the other answers I've seen on SO, I need to do this entirely within the Redis console without the use of any other scripting or Bash. The reason being that I need to execute this from within the Console functionality of the Azure Cache for Redis portal. I am able to select the keys I want using SCAN 0 MATCH *mypattern*
but, I don't know of any way to "pipe" this to the DEL
command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果这对其他任何人都有帮助,这是我发现对我有用的答案。
evar eval“ return redis.call('del',unfack(redis.call)('scan',0,'match',argv [1])[2]))” 0 *mypattern *
the内部
redis.call('scan')
命令找到匹配的所有键*mypattern*
(其中任何位于其中的任何“ mypattern”的键)。该命令的返回值的第二个索引位置是键的列表,然后将其解开并传递到ofterredis.call('del')
命令,该命令从缓存中删除对象。请注意,如果没有与模式匹配的键,这将返回错误。对于我的用例,这是可以的,所以我没有进一步探索它,但是可能有办法解决这个问题。
In case this is helpful to anyone else, here is the answer I found that worked for me.
EVAL "return redis.call('del', unpack(redis.call('scan', 0, ‘MATCH', ARGV[1])[2]))" 0 *mypattern*
The inner
redis.call('scan')
command finds all keys matching*mypattern*
(any key with "mypattern" anywhere in it). The second index position of the return value of this command is the list of the keys which is then unpacked and passed to the outerredis.call('del')
command which deletes the objects from the cache.Note that this will return an error if there are no keys matching the pattern. This was ok for my use case so I did not explore it further, but there may be a way around this.