SDK
SDK Javascript v6.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

set #

Creates a key holding the provided value, or overwrites it if it already exists.

[Redis documentation]

Arguments #

set(key, value, [options]);

ArgumentsTypeDescription
key
string
Key
value
*
Value
options
object
Optional query arguments

options #

The options arguments can contain the following option properties:

PropertyType (default)Description
ex
integer
Adds an expiration delay to the key, in seconds
nx
boolean (false)
If true, do not set the key if it already exists
px
integer
Adds an expiration delay to the key, in milliseconds
queuable
boolean (true)
If true, queues the request during downtime, until connected to Kuzzle again
xx
boolean (false)
If true, sets the key only if it already exists

Note: the ex and px options are mutually exclusive; setting both options ends up in a BadRequestError error. Same thing goes for nx and xx.

Resolve #

Resolves once the operation succeeds.

Usage #

try {
  await kuzzle.ms.set('foo', 'bar');
  // Prints: bar
  console.log(await kuzzle.ms.get('foo'));
} catch (error) {
  console.error(error.message);
}