Easy Tutorial
❮ Hashes Hgetall Sets Sunion ❯

Redis SET Command

Redis Strings

The Redis SET command is used to set the value of a given key. If the key already holds a value, SET overwrites the old value, regardless of its 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 prior to Redis 2.6.12, the SET command always returns "OK".

Starting from Redis 2.6.12, SET returns "OK" only if the set operation is successfully completed.

Examples

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

# Setting a non-existing key

redis 127.0.0.1:6379> SET key "value"
OK

redis 127.0.0.1:6379> GET key
"value"

# Setting an existing key

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

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

Redis Strings

❮ Hashes Hgetall Sets Sunion ❯