Home > @imqueue/rpc > RedisCache > set

RedisCache.set() method

Stores the given value in the cache under the given key. If TTL is specified, the cached value will expire after the given number of milliseconds. If the NX argument is set to true, the key:value pair is created only if it does not exist yet. The given value can be any JSON-compatible object and will be serialized automatically.

Signature:

set(key: string, value: any, ttl?: number, nx?: boolean): Promise<boolean>;

Parameters

Parameter

Type

Description

key

string

key to store the value under

value

any

value to store

ttl

number

(Optional) time-to-live in milliseconds

nx

boolean

(Optional) store only if the key does not exist yet

Returns:

Promise<boolean>

{Promise}