问题描述
我想在我的作业中使用 Redis 的 HSCAN 命令,但我不知道它是如何工作的.这个命令的Redis官方页面(http://redis.io/commands/hscan)给了我空白页.
我正在获取连续的输入数据并将它们即时保存在 Redis 中的多个散列中,我想在稍后的时间点遍历所有这些数据.
我正在使用以下命令来保存我的数据
HMSET myhash ordertype "neworder" order_ts "1234" act_type "order_ack" ack_ts "1240"HMSET myhash2 ordertype "neworder" order_ts "2234" act_type "order_ack" ack_ts "2240"谁能给我一些关于如何使用 HSCAN 的例子?
就我而言,我想获得以下输出
1) myhash
2) myhash2
3) myhash3
.
.
.
.
命令
开始一个完整的哈希扫描:
HSCAN myhash 0
使用与以下模式匹配的字段开始哈希扫描:
HSCAN myhash 0 MATCH order_*
使用匹配模式的字段开始哈希扫描并强制扫描命令执行更多扫描:
HSCAN myhash 0 MATCH order_* COUNT 1000
注意
不要忘记 MATCH 每次迭代都可以返回很少或没有元素,如 文档:
需要注意的是 MATCH 过滤器是在在返回数据之前从集合中检索元素给客户.这意味着如果模式匹配很少集合中的元素,SCAN 可能不会返回任何元素大多数迭代.
这就是为什么您可以使用 COUNT
强制对每次迭代进行更多扫描.
[更新] 正如 Didier Spezia 指定的那样,您需要 Redis 2.8+ 使用 *SCAN 命令.
I want to use Redis's HSCAN command in my assignment but I have no idea how it works. Redis's official page (http://redis.io/commands/hscan) for this command gives me blank page.
I am getting continuous input data and saving them instantaneously in multiple hashes in Redis and I would like to iterate through all of them at later point of time.
I'm using following command to save my data
HMSET myhash ordertype "neworder" order_ts "1234" act_type "order_ack" ack_ts "1240" HMSET myhash2 ordertype "neworder" order_ts "2234" act_type "order_ack" ack_ts "2240"
Can anyone give me some examples of how to use HSCAN?
In my case I would like to get following output
1) myhash
2) myhash2
3) myhash3
.
.
.
.
Commands
Start a full hash scan with:
HSCAN myhash 0
Start a hash scan with fields matching a pattern with:
HSCAN myhash 0 MATCH order_*
Start a hash scan with fields matching a pattern and forcing the scan command to do more scanning with:
HSCAN myhash 0 MATCH order_* COUNT 1000
Note
Don't forget that MATCH can return little to no element for each iteration, as explained in the documentation:
And that's why you can use COUNT
to force more scanning for each iteration.
[Update] As Didier Spezia specified, you'll need Redis 2.8+ to use the *SCAN commands.
这篇关于如何在Redis中使用HSCAN命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!