Skip to main content
Use ZADD to add members with a score to a sorted set, or to change the score of members that are already there. Members are kept ordered by score, and members with equal scores are ordered lexicographically, which is what makes range queries by score or by member name possible. Scores are double precision floats and accept +inf and -inf. The key is created on first use, and the reply counts the members that were added. NX only adds new members and never changes an existing score, while XX only updates members that already exist. GT and LT update a score only when the new one is greater or less than the current one, which is how you keep a running maximum or minimum, such as a high score or an earliest deadline, without reading the old value first. CH makes the reply count every member that changed, added or updated, instead of only the new ones. INCR treats the given score as an increment and returns the member’s new score, behaving like ZINCRBY for a single member and returning null when a condition prevented the change.

Syntax

Arguments

Important points

  • NX cannot be combined with XX, GT, or LT, and GT and LT cannot be used together.
  • 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.
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.