set #
Creates a key holding the provided value, or overwrites it if it already exists.
Arguments #
set(key, value, [options]);
Arguments | Type | Description |
---|---|---|
key | string | Key |
value | * | Value |
options | object | Optional query arguments |
options #
The options
arguments can contain the following option properties:
Property | Type (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 |
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 |
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);
}
Edit this page on Github(opens new window)