Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Command

SMEMBERS

Returns every member of the set stored at a key. The result contains the set's complete, unordered membership.

Since
Redis Open Source 1.0.0

How it works

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.

Syntax

SMEMBERS key

Parameters

NameTypeDescription
keykeyThe key containing the set whose members should be returned.

Returns

All members of the set at the key; RESP2 represents them as an array reply, while RESP3 represents them as a set reply.

Key points

  • Use SMEMBERS to retrieve the complete membership of a Redis set.
  • Its sole argument is the key whose value is the target set.
  • The command has existed since Redis Open Source 1.0.0.
  • Redis classifies SMEMBERS as a read operation for set data and marks it as slow.

Common mistakes

  • SMEMBERS does not impose ordering; treat the result as a set rather than relying on element positions.
  • Retrieving a large set can be expensive because the command processes every member.

Example: Read all set members

SADD myset "Hello" "World"
SMEMBERS myset

Adds two values to a Redis set, then retrieves every member.

When to use it

Read set membership

Inspect the current contents of a set during application logic or debugging.

Materialize a set

Load all participants, tags, or identifiers represented by a set when the collection is suitably small.

Support set-based workflows

Compare a set's full contents with another collection after retrieving its members.

Interview questions

QWhat does SMEMBERS return, and what is its complexity?

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.

QWhat argument does SMEMBERS require, and what does the reply look like?

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.

QWhen was SMEMBERS introduced and what kind of operation is it?

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.

  • SADD
  • SINTER
  • SSCAN
  • SREM

Source: Smembers. Checked 2026-10-16.