The Redis SSCAN command is used to iterate over the elements of a set. It is based on the SCAN command.

Syntax

The basic syntax of the SSCAN command is as follows:

1
SSCAN key cursor [MATCH pattern] [COUNT count]

Available Since

Redis version >= 2.8.0

Time Complexity

O(1) for every call.

O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection.

ACL Categories

@read, @set, @slow

Return Value

Returns an array. specifically, an array with two elements:

  • The first element is a Bulk string reply that represents an unsigned 64-bit number, the cursor.
  • The second element is an Array reply with the names of scanned members.

Example

1
2
3
4
5
6
7
127.0.0.1:6379> SADD myset Johnson Jack Tim Paul
(integer) 4
127.0.0.1:6379> SSCAN myset 0 MATCH J*
1) "0"
2) 1) "Johnson"
2) "Jack"
127.0.0.1:6379>