English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis SET Command

Redis Strings (string)

The Redis SET command is used to set the value of the given key. If the key already stores another value, SET overwrites the old value and ignores the type.

Syntax

Basic Syntax of Redis SET Command

redis 127.0.0.1:6379> SET KEY_NAME VALUE

Available Version

>= 1.0.0

Return Value

In Redis 2.6.12 In previous versions, the SET command always returned OK.

From Redis 2.6.12 Starting from this version, SET returns OK only after the setting operation is successfully completed.

Online Example

Firstly, we create a key and set its value in Redis.

# Set the non-existing key
redis 127.0.0.1:6379> SET key "value"
OK
redis 127.0.0.1:6379> GET key
"value"
# Set the 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 (string)