method
RedisClient.msetnx
): Promise<number>;
Set multiple keys to multiple values, only if none of the keys exist
MSETNX performs no operation at all if even a single key already exists.
This lets you set several keys representing fields of a single logical object and guarantee that either all of them or none are set.
MSETNX is atomic: all given keys are set at once, so clients never see some of the keys updated while others are unchanged.
@param keyValuePairs
Alternating keys and values (key1, value1, key2, value2, ...)
@returns
Promise that resolves with 1 if all keys were set, 0 if no key was set
// Returns 1 if keys don't exist
await redis.msetnx("key1", "value1", "key2", "value2");
// Returns 0 if any key already exists
await redis.msetnx("key1", "newvalue", "key3", "value3");Referenced types
type KeyLike = string | ArrayBufferView | Blob