How to Get a Key’s Type in Redis

If you know the name of a key in Redis, but you want to find out it’s type (eg, string, list, hash, set, etc), look no further than the TYPE command. This command returns the string representation of the type of the value at the given key.

Example

Here’s an example to demonstrate:

TYPE username

Result:

string

In this case, the key called username holds a string.

Here’s the output from my terminal when I run the command against more keys:

127.0.0.1:6379> TYPE username
string
127.0.0.1:6379> TYPE logins
set
127.0.0.1:6379> TYPE customer
hash
127.0.0.1:6379> TYPE animals_desc
list

The different types that can be returned are: string, list, set, zset, hash and stream.