如何在Redis中使用HSCAN命令? [英] How to use HSCAN command in Redis?

查看:56
本文介绍了如何在Redis中使用HSCAN命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的作业中使用 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:

It is important to note that the MATCH filter is applied after elements are retrieved from the collection, just before returning data to the client. This means that if the pattern matches very little elements inside the collection, SCAN will likely return no elements in most iterations.

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命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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