Redis Sets: SSCAN
Redis SSCAN Command
The Redis SSCAN command is used in order to incrementally iterate over a collection of elements.
Basic usage of SSCAN
- SSCAN is a cursor based iterator. This means that at every call of the command, the server returns an updated cursor that the user needs to use as the cursor argument in the next call.
- An iteration starts when the cursor is set to 0, and terminates when the cursor returned by the server is 0. The following is an example of SSCAN iteration:
Syntax:
SSCAN KEY [MATCH pattern] [COUNT count]
Available since:
2.8.0.
Return Value:
Array reply.
Return Value Type:
Integer
Example: Redis SSCAN
127.0.0.1:6379> SADD mytestset M1 M2 M3 N1 N2 N3 O1 O2 O3 P1 P2 P3 Q1 Q2 Q3 (integer) 15 127.0.0.1:6379> SSCAN mytestset 0 1) "3" 2) 1) "O2" 2) "Q3" 3) "P1" 4) "O3" 5) "M1" 6) "N1" 7) "P2" 8) "N3" 9) "Q2" 10) "N2" 11) "O1" 127.0.0.1:6379> SSCAN mytestset 3 1) "0" 2) 1) "M2" 2) "P3" 3) "M3" 4) "Q1"
Example: Redis SSCAN : using count
127.0.0.1:6379> SSCAN mytestset 0 COUNT 18 1) "0" 2) 1) "O2" 2) "Q3" 3) "P1" 4) "O3" 5) "M1" 6) "N1" 7) "P2" 8) "N3" 9) "Q2" 10) "N2" 11) "O1" 12) "M2" 13) "P3" 14) "M3" 15) "Q1"
Example: Redis SSCAN : using pattern
127.0.0.1:6379> SSCAN mytestset 0 MATCH N* 1) "3" 2) 1) "N1" 2) "N3" 3) "N2" 127.0.0.1:6379> SSCAN mytestset 0 MATCH *3* 1) "3" 2) 1) "Q3" 2) "O3" 3) "N3" 127.0.0.1:6379> SSCAN mytestset 0 MATCH *3* COUNT 20 1) "0" 2) 1) "Q3" 2) "O3" 3) "N3" 4) "P3" 5) "M3"
Previous:
Redis Sets SUNIONSTORE
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics