method

RedisClient.type

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

Determine the type of value stored at key

@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