SSCAN

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

Scan members in small batches

Usage: sscan key cursor.
SMEMBERS returns every member at once, while SSCAN returns about 10 members per call.
When there are many members, specify the next cursor and scan again.
If a set has many members, SMEMBERS can take a long time and the server may appear to stall.
SSCAN is the alternative for that case.
When the scan is complete, the next cursor is 0.

Example

Command>sadd myset A1 A2 A3 B1 B2 B3 C1 C2 C3 D1 D2 D3 E1 E2 E3
Result>15
Command>sscan myset 0
Result>next cursor -> 11
0) E1
1) A2
2) C2
...
10) B1
Command>sscan myset 11
Result>next cursor -> 0
0) A1
1) D1
2) C3
3) C1


COUNT option

Usage: sscan key cursor count 20.
The number of members returned is not always exactly the specified COUNT. Redis adjusts the count based on processing time.

Example

Command>sscan myset 0 count 20
Result>next cursor -> 0
0) E1
1) A2
2) C2
...
14) C1


MATCH pattern

Usage: sscan key cursor match pattern.
The pattern is GLOB style.

Example

Command>sscan myset 0 match B*
Result>next cursor -> 0
0) B3
1) B2
2) B1


Syntax

SSCAN key cursor [MATCH pattern] [COUNT count]

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

<< SRANDMEMBER SSCAN SORTED SETS Introduction >>

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