Read set membership
Inspect the current contents of a set during application logic or debugging.
Redis · Command
Returns every member of the set stored at a key. The result contains the set's complete, unordered membership.
SMEMBERS reads the complete set stored at the specified key and returns its members as an unordered collection. It is equivalent to running SINTER with that one key, and its work grows linearly with the set size.
SMEMBERS key| Name | Type | Description |
|---|---|---|
key | key | The key containing the set whose members should be returned. |
All members of the set at the key; RESP2 represents them as an array reply, while RESP3 represents them as a set reply.
SADD myset "Hello" "World"
SMEMBERS mysetAdds two values to a Redis set, then retrieves every member.
Inspect the current contents of a set during application logic or debugging.
Load all participants, tags, or identifiers represented by a set when the collection is suitably small.
Compare a set's full contents with another collection after retrieving its members.
SMEMBERS returns all members held by the set at a key. Its time complexity is O(N), where N is the set cardinality.
Follow-up: How would you read a very large set incrementally? Use SSCAN, which iterates through set members in batches instead of retrieving the entire collection at once.
The command takes one required argument: the key containing the set. The result is an array in RESP2 and a set in RESP3.
Follow-up: Does SMEMBERS sort its output? No; set membership has no ordering guarantee, so consumers should not depend on result order.
SMEMBERS is a read-only set command that returns every member stored at the supplied key. It has been available since Redis Open Source 1.0.0.
Follow-up: What happens if the key contains a non-set value? Redis reports a wrong-type error rather than treating the value as a set.
SADDSINTERSSCANSREM