HSCAN

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Get fields and members in batches of a given count

The usage is hscan key cursor.
When there are many fields, specify a cursor and iterate. When all fields have been scanned, the next cursor is 0.
This is similar to repeatedly querying with hmget key f1, f2.
In the example there are not many fields, so they were all returned at once.

Example

Command>hmset myhash f1 v1 f2 v2 f3 v3 c4 v4 c5 v5 c6 v6
Result>OK
Command>hscan myhash 0
Result>next cursor -> 0
0) f1 -> v1
1) f2 -> v2
2) f3 -> v3
3) c4 -> v4
4) c5 -> v5
5) c6 -> v6


COUNT can be used

The usage is hscan key cursor count 5.
The number of returned fields does not always match the specified count exactly. Redis adjusts the count considering processing time.

Example

Command>hscan myzip 0 count 5
Result>next cursor -> 0
0) f1 -> v1
1) f2 -> v2
2) f3 -> v3
3) c4 -> v4
4) c5 -> v5
5) c6 -> v6


MATCH pattern can be used

The usage is hscan key cursor match pattern.
The pattern is applied to fields. It is a GLOB-style pattern.

Example

Command>hscan myset 0 match c*
Result>next cursor -> 0
0) c4 -> v4
1) c5 -> v5
2) c6 -> v6


Syntax

HSCAN key cursor [MATCH pattern] [COUNT count]

  • Available since version 2.8.0.
  • Time complexity is O(1) per call.
Related commands HMGET
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< HSETNX HSCAN HRANDFIELD >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.