Sorted Set

ZADD

Add a member to a sorted set, or update its score if it already exists.

Arguments

keybodystringrequired

The key of the sorted set.

optionsbody
xxbodyboolean

Only update elements that already exist. Never add elements.

nxbodyboolean

Only add new elements. Never update elements.

chbodyboolean

Return the number of elements added or updated.

incrbodyboolean

When this option is specified ZADD acts like ZINCRBY. Only one score-element pair can be specified in this mode.

gtbodyboolean

Only update existing elements if the new score is greater than the current score. Add element without a check if it does not exist.

ltbodyboolean

Only update existing elements if the new score is less than the current score. Add element without a check if it does not exist.

Response

integerrequired

The number of elements added to the sorted sets, not including elements already existing for which the score was updated.

If ch was specified, the number of elements that were updated.

If incr was specified, the new score of member.

Simple
await redis.zadd(    "key",     { score: 2, member: "member" },     { score: 3, member: "member2"},);
XX
await redis.zadd(    "key",    { xx: true },    { score: 2, member: "member" },)
NX
await redis.zadd(    "key",    { nx: true },    { score: 2, member: "member" },)
CH
await redis.zadd(    "key",    { ch: true },    { score: 2, member: "member" },)
INCR
await redis.zadd(    "key",    { cincrh: true },    { score: 2, member: "member" },)
GT
await redis.zadd(    "key",    { gt: true },    { score: 2, member: "member" },)
LT
await redis.zadd(    "key",    { lt: true },    { score: 2, member: "member" },)
Loading search…