Redis SET Command
Redis SET command is used to set the value of a given key. If the key already stores another value, SET overwrites the old value, regardless of type.
Syntax
The basic syntax of the Redis SET command is as follows:
redis 127.0.0.1:6379> SET KEY_NAME VALUE
Available Versions
>= 1.0.0
Return Value
In versions before Redis 2.6.12, the SET command always returned OK.
Starting from Redis 2.6.12, SET returns OK only when the set operation completes successfully.
Examples
First, we create a key in Redis and set a value.
# 对不存在的键进行设置 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"Other Extensions
Redis String