SDK
SDK Javascript v7.x
2

zadd #

Adds elements to a sorted set.

If the key does not exist, it is created, holding an empty sorted set.

If the key already exists but does not hold a sorted set, an error is returned.

If a member to insert is already in the sorted set, its score is updated and the member is reinserted at the right position in the set.

[Redis documentation]

Arguments #

zadd(key, elements, [options]);

ArgumentsTypeDescription
key
string
Sorted set key
elements
object[]
Elements to add
options
object
Optional query arguments

elements #

The elements array lists the elements to add to the sorted set. Each element object has the following properties:

PropertiesTypeDescription
member
string
Member value
score
string
Member score

options #

The options arguments can contain the following option properties:

PropertyType (default)Description
ch
boolean (false)
If true, instead of returning the number of added elements, returns the number of changes performed
incr
boolean (false)
If true, instead of adding elements, increments the existing member with the provided score. Only one element can be specified if this option is set
nx
boolean (false)
If true, only adds new elements, without altering existing ones
queuable
boolean (true)
If true, queues the request during downtime, until connected to Kuzzle again
timeout
number

(-1)
Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely
triggerEvents
boolean

(false)
If set to true, will trigger events even if using Embeded SDK. You should always ensure that your events/pipes does not create an infinite loop.
Available since Kuzzle 2.31.0
xx
boolean (false)
If true, ignores new elements, alters only existing ones

Resolve #

Resolves to the number of added elements or, if the ch option is set, resolves to the number of changes performed.

Usage #

try {
  await kuzzle.ms.zadd('ssetfoo', [
    {member: 'foo', score: '42'},
    {member: 'bar', score: '4'},
    {member: 'baz', score: '-272.15'}
  ]);
  // Prints:
  // [ { member: 'baz', score: -272.15 },
  //   { member: 'bar', score: 4 },
  //   { member: 'foo', score: 42 } ]
  console.log(await kuzzle.ms.zrange('ssetfoo', 0, -1));
} catch (error) {
  console.error(error.message);
}