Latest web development tutorials

Redis SET command

Redis string (string)

Redis SET command is used to set the value of a given key. If the key is already stored other value, SET will overwrite the old value, and ignore type.

grammar

redis SET command basic syntax is as follows:

redis 127.0.0.1:6379> SET KEY_NAME VALUE

Available versions

> = 1.0.0

return value

Redis 2.6.12 In previous versions, SET command always returns OK.

Starting Redis 2.6.12 version, SET when setting the operation completes successfully, it returns OK.

Examples

First, we create a key and set the value in redis.

# 对不存在的键进行设置

redis 127.0.0.1:6379> SET key "value"
OK

redis 127.0.0.1:6379> GET key
"value"


# 对已存在的键进行设置

redis 127.0.0.1:6379> SET key "new-value"
OK

redis 127.0.0.1:6379> GET key
"new-value"

Redis string (string)