ZSCAN

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

Scan scores and members in batches

Usage: zscan key cursor.
If there are many members, iterate with a cursor. When the scan is complete, the next cursor is 0.
Similar to iterating with zrange key start stop.
In this example there are not many members, so all were returned in one call.

Example

Command>zadd myzip 1 A1 2 A2 3 A3 4 B1 5 B2 6 B3 7 C1 8 C2 9 C3
Result>9
Command>sscan myset 0
Result>next cursor -> 0
0) 1 -> A1
1) 2 -> A2
2) 3 -> A3
...
8) 9 -> C3


count can be used

Usage: zscan key cursor count 10.
The number of returned members may not exactly match count. Redis adjusts the count considering processing time.

Example

Command>zscan myzip 0 count 5
Result>next cursor -> 0
0) E1
1) A2
2) C2
...
8) 9 -> C3


pattern can be used

Usage: zscan key cursor match pattern.
The pattern is applied to members.
It is a GLOB-style pattern.

Example

Command>zscan myset 0 match B*
Result>next cursor -> 0
0) 4 -> B1
1) 5 -> B2
2) 6 -> B3


Syntax

ZSCAN key cursor [MATCH pattern] [COUNT count]

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

<< ZDIFFSTORE ZSCAN ZPOPMIN >>

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