The related commands for Redis string data types are used to manage Redis string values, with the following basic syntax:
Grammar
- Redis 127.0. 0.1:6379> COMMAND key_name
Instance
Redis 127.0.0.1:6379> SET w3ckey redis ok redis 127.0.0.1:6379> GET w3ckey "Redis"
In the above example we used the SET and GET command, the key is W3ckey.
Redis string command
The following table lists the commonly used Redis string commands:
Serial Number |
Command and Description |
1 |
Set key value sets the values of the specified key |
2 |
Get key gets the value of the specified key. |
3 |
GETRANGE Key start end returns the substring of the string value in key |
4 |
Getset key value sets the value of the given key to value, and returns the old value of the key. |
5 |
Getbit key offset to the string value stored by key, gets the bit on the specified offset (bit). |
6 |
MGET Key1 [Key2 ...] gets the value of all (one or more) given key. |
7 |
Setbit key offset value Sets or clears a bit (bit) on the specified offset for the string value stored by key. |
8 |
Setex Key seconds values associates the value to key and sets the expiration time of the key to seconds (in seconds). |
9 |
Setnx key value sets the value of key only if the key does not exist. |
10 |
SETRANGE key offset value is written with the value parameter to the string value stored by the key, starting at offset offsets. |
11 |
STRLEN Key returns the length of the string value stored by key. |
12 |
MSET key value [key value ...] sets one or more key-value pairs at the same time. |
13 |
Msetnx key value [key value ...] sets one or more key-value pairs at the same time, when and only if all given key does not exist. |
14 |
Psetex key milliseconds value This command is similar to the Setex command, but it sets the lifetime of the key in milliseconds, rather than in seconds, as in the Setex command. |
15 |
INCR key adds a number value stored in key. |
16 |
Incrby key increment adds the value stored by key to the given increment value (increment). |
17 |
Incrbyfloat key increment adds the value stored by key to the given floating-point increment value (increment). |
18 |
DECR key Subtract one of the numeric values stored in key. |
19 |
Decrby key Decrement key stores the value minus the given decrement value (decrement). |
20 |
APPEND key value if key already exists and is a string, the APPEND command appends value to the end of the original value of the key. |
Redis string (string)