Upstash Documentation

SDIFF

Get set difference.
2 min read

Use SDIFF to get the members of the first set that are not present in any of the other sets.

Keys that do not exist count as empty sets, so a missing first key yields an empty result. The difference is computed on the fly and nothing is stored; use SDIFFSTORE to keep the result.

It answers questions of the form "who is in A but not in B", such as users who signed up but never converted. The cost grows with the size of the sets involved, so on large sets prefer storing the result and reusing it.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<key>YesYesRedis key targeted by the command.

Response#

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.

ProtocolReply
RESP2Array of bulk-string members
RESP3Set of bulk-string members
Note

Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples#

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.

Redis CLI
@upstash/redis
upstash_redis
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs