Mmsetnx
Bun

method

RedisClient.msetnx

...keyValuePairs: KeyLike[]
): Promise<number>;

Set multiple keys to multiple values, only if none of the keys exist

Sets the given keys to their respective values. MSETNX will not perform any operation at all even if just a single key already exists.

Because of this semantic, MSETNX can be used in order to set different keys representing different fields of a unique logic object in a way that ensures that either all the fields or none at all are set.

MSETNX is atomic, so all given keys are set at once. It is not possible for clients to see that some of the keys were 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