Upstash Documentation

ZDIFF

Get sorted set difference.
2 min read

Use ZDIFF to get the members of the first sorted set that do not appear in any of the others.

<numkeys> states how many keys follow. Scores come from the first set and are returned only when WITHSCORES is given, and the result keeps the ordering of that set. Keys that do not exist count as empty.

The result is computed on each call and not stored; use ZDIFFSTORE to keep it. This is how you exclude one group from a ranking, for example dropping already-seen items from a scored feed.

Syntax#

Arguments#

ArgumentRequiredRepeatableDescription
<numkeys>YesNoNumber of key arguments that follow.
<key>YesYesRedis key targeted by the command.
WITHSCORESNoNoInclude sorted-set scores.

Important points#

  • numkeys must equal the number of key arguments that immediately follow it.
  • Pair-based results may be flattened into one alternating array in RESP2 while RESP3 preserves nested pairs or a map.
  • RESP2 represents floating-point reply values as bulk strings; RESP3 may use native double replies. Client libraries commonly decode either form to a language number.

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 members, or flat member/score array with WITHSCORES
RESP3Array of members, or array of member/score pairs with WITHSCORES
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
Note

This command is not supported yet in @upstash/redis.

upstash_redis
ioredis
node-redis
redis-py
go-redis
jedis
redis-rs