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

Redis Strings (String)

The commands related to the Redis string data type are used to manage Redis string values, and the basic syntax is as follows:

Syntax

redis 127.0.0.1:6379> COMMAND KEY_NAME

Online example

redis 127.0.0.1:6379> SET w3codeboxkey redis
OK
redis 127.0.0.1:6379> GET w3codeboxkey
"redis"

In the above examples, we used SET and GET Command, key is w3codeboxkey.

Redis string commands

The following table lists commonly used redis string commands:

Serial numberCommand and description
1SET key value
Set the value of the specified key
2GET key
Get the value of the specified key.
3GETRANGE key start end
Return the substring of the string value in the key.
4GETSET key value
Set the value of the given key to value and return the old value of the key.
5GETBIT key offset
Get the bit at the specified offset of the string value stored at the key.
6MGET key1 [key2..]
Get all (one or more) values of the given key.
7SETBIT key offset value
Set or clear the bit at the specified offset of the string value stored at the key.
8SETEX key seconds value
Associate the value value with the key and set the expiration time of the key to seconds (in seconds).
9SETNX key value
Set the value of the key only if the key does not exist.
10SETRANGE key offset value
Use the value parameter to overwrite the string value stored at the given key, starting from the offset offset.
11STRLEN key
Return the length of the string value stored at key.
12Set the value of the key to the specified value.
Set one or more keys at the same time-value if the value is set.
13MSETNX key value [key value ...]
Set one or more keys at the same time-value if all given keys do not exist.
14PSETEX key milliseconds value
This command is similar to the SETEX command, but it sets the expiration time of the key in milliseconds instead of seconds as the SETEX command does.
15INCR key
Increase the numeric value stored at key by one.
16INCRBY key increment
Increase the value stored at key by the given increment.
17INCRBYFLOAT key increment
Increase the value stored at key by the given floating-point increment.
18DECR key
Decrease the numeric value stored at key by one.
19DECRBY key decrement
Decrease the value stored at key by the given decrement.
20APPEND key value
If the key already exists and it is a string, the APPEND command will append the specified value to the end of the original value (value) of the key.

For more commands, please refer to:https://redis.io/commands