Mtype
Bun

method

RedisClient.type

key: KeyLike
): Promise<'string' | 'stream' | 'none' | 'set' | 'list' | 'zset' | 'hash'>;

Determine the type of value stored at key

The TYPE command returns the string representation of the type of the value stored at key. The different types that can be returned are: string, list, set, zset, hash and stream.

@param key

The key to check

@returns

Promise that resolves with the type of value stored at key, or "none" if the key doesn't exist

await redis.set("mykey", "Hello");
console.log(await redis.type("mykey")); // "string"

await redis.lpush("mylist", "value");
console.log(await redis.type("mylist")); // "list"

await redis.sadd("myset", "value");
console.log(await redis.type("myset")); // "set"

await redis.hset("myhash", "field", "value");
console.log(await redis.type("myhash")); // "hash"

console.log(await redis.type("nonexistent")); // "none"

Referenced types

type KeyLike = string | ArrayBufferView | Blob