Redis SET command
The 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 Version
= 1.0.0
Return Value
In versions prior to 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.
Example
First, we create a key in redis and set its value.
# Set a key that does not exist
redis 127.0.0.1:6379> SET key "value"
OK
redis 127.0.0.1:6379> GET key
"value"
# Set existing key
redis 127.0.0.1:6379> SET key "new-value"
OK
redis 127.0.0.1:6379> GET key
"new-value"
Redis string