ZADD
Syntax
Section titled “Syntax”ZADD key [NX | XX] [GT | LT] [CH] [INCR] score member [score member...]
ZADD adds all the specified members with the specified scores to the sorted set stored at key.
The score of the member should be an integer and two members can have the same score. Here are the options supported by the command:
- NX: Only add new elements and do not update existing elements
- XX: Only update existing elements and do not add new elements
- GT: Only add new elements if the score is greater than the existing score
- LT: Only add new elements if the score is less than the existing score
- CH: Modify the return value from the number of new elements added to the total number of elements changed
- INCR: When this option is specified, the scores provided are treated as increments to the score of the existing elements
The command by default returns the number of elements added to the sorted set.
Examples
Section titled “Examples”localhost:7379> ZADD users 10 u1OK 1localhost:7379> ZADD users 5 u2OK 1localhost:7379> ZADD users 15 u3OK 1localhost:7379> ZADD users 12 u4OK 1localhost:7379> ZADD users 10 u1OK 0localhost:7379> ZADD users CH 11 u1OK 1