TYPE command in redis

TYPE key

Return the type of the value stored at the key in form of a string. The type can be one of "none", "string", "list", and "set". "none" is returned if the key does not exist.

Time complexity: O(1)

RETURN VALUE

Status code reply, specifically:

"none" if the key does not exist

"string" if the key contains a String value

"list" if the key contains a List value

"set" if the key contains a Set Value

Syntax:

TYPE key

Example 1: When the key is present

redis:6379> SET myKey1 1000
"OK"
redis:6379> SADD myKey2 10 20 30
(integer) 3
redis:6379> HSET myKey3 field 100
(integer) 1
redis:6379> TYPE myKey1
"string"
redis:6379> TYPE myKey2
"set"
redis:6379> TYPE myKey3
"hash"


Example 2: When the key is not present

redis:6379> TYPE key1
"none"

Output

none


No comments:

Post a Comment