Redis 扫描计数:如何强制 SCAN 返回匹配模式的所有键? [英] Redis scan count: How to force SCAN to return all keys matching a pattern?

查看:41
本文介绍了Redis 扫描计数:如何强制 SCAN 返回匹配模式的所有键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出存储在与 redis 模式匹配的键列表中的值.我尝试使用 SCAN 以便稍后我可以使用 MGET 来获取所有值,问题是:

I am trying to find out values stored in a list of keys which match a pattern from redis. I tried using SCAN so that later on i can use MGET to get all the values, The problem is:

SCAN 0 MATCH "foo:bar:*" COUNT 1000

不返回任何值而

SCAN 0 MATCH "foo:bar:*" COUNT 10000

返回所需的键.如何强制 SCAN 查看所有现有密钥?我是否必须为此研究 lua?

returns the desired keys. How do i force SCAN to look through all the existing keys? Do I have to look into lua for this?

推荐答案

使用下面的代码,您将扫描光标 0 处的第 1000 个对象

With the code below you will scan the 1000 first object from cursor 0

SCAN 0 MATCH "foo:bar:*" COUNT 1000 

结果,你会得到一个新的光标来回忆

In result, you will get a new cursor to recall

SCAN YOUR_NEW_CURSOR MATCH "foo:bar:*" COUNT 1000

要扫描 1000 个下一个对象.然后,当您将 COUNT 从 1000 增加到 10000 并检索数据时,您会扫描更多键,然后在您的情况下匹配更多键.

To scan 1000 next object. Then when you increase COUNT from 1000 to 10000 and retrieve data you scan more keys then in your case match more keys.

要扫描整个列表,您需要调用 SCAN 直到光标给出响应返回零(即整个扫描)

To scan the entire list you need to recall SCAN until the cursor give in response return zero (i.e entire scan)

使用 INFO 命令获取您的密钥数量,例如

Use INFO command to get your amount of keys like

db0:keys=YOUR_AMOUNT_OF_KEYS,expires=0,avg_ttl=0

db0:keys=YOUR_AMOUNT_OF_KEYS,expires=0,avg_ttl=0

然后调用

SCAN 0 MATCH "foo:bar:*" COUNT YOUR_AMOUNT_OF_KEYS

这篇关于Redis 扫描计数:如何强制 SCAN 返回匹配模式的所有键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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