Latest web development tutorials

Redis Get command

Redis string (string)

Redis Get command is used to obtain the value of the specified key. If the key does not exist, returns nil. If the key value is not a string type store, an error is returned.

grammar

redis Get basic command syntax is as follows:

redis 127.0.0.1:6379> GET KEY_NAME

Available versions

> = 1.0.0

return value

The return value of the key, if the key does not exist, returns nil. If the key is not a string type, an error is returned.

Examples

# 对不存在的 key 或字符串类型 key 进行 GET

redis> GET db
(nil)

redis> SET db redis
OK

redis> GET db
"redis"


# 对不是字符串类型的 key 进行 GET

redis> DEL db
(integer) 1

redis> LPUSH db redis mongodb mysql
(integer) 3

redis> GET db
(error) ERR Operation against a key holding the wrong kind of value

Redis string (string)