Upstash Documentation

SDIFFSTORE

Store set difference.
2 min read

Use SDIFFSTORE to compute the difference between sets and store it in another key.

The destination holds the members of the first source set that are absent from all the others. It is overwritten if it already exists, and deleted when the result is empty. The reply is the number of members stored.

Storing rather than returning the result is what you want when the difference is large or is used more than once, since the destination is an ordinary set that can be paged through or fed into further set operations.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<destination>YesNoRedis key used as destination.
<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
RESP2Integer
RESP3Integer
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