Mrenamenx
Bun

method

RedisClient.renamenx

key: KeyLike,
newkey: KeyLike
): Promise<number>;

Rename a key to a new key only if the new key does not exist

Renames key to newkey only if newkey does not yet exist. If key does not exist, an error is returned.

@param key

The key to rename

@param newkey

The new key name

@returns

Promise that resolves with 1 if the key was renamed, 0 if newkey already exists

await redis.set("mykey", "Hello");
await redis.renamenx("mykey", "myotherkey"); // Returns 1
await redis.set("mykey2", "World");
await redis.renamenx("mykey2", "myotherkey"); // Returns 0 (myotherkey exists)

Referenced types

type KeyLike = string | ArrayBufferView | Blob