Redis String
The commands related to the Redis string data type are used to manage Redis string values. The basic syntax is as follows:
Syntax
redis 127.0.0.1:6379> COMMAND KEY_NAME
Example
redis 127.0.0.1:6379> SET examplekey redis OK redis 127.0.0.1:6379> GET examplekey "redis"
In the above example we used theSETandGETcommand, with the key beingexamplekey。
Redis String Commands
The following table lists commonly used Redis string commands:
| No. | Command and description |
|---|---|
| 1 | SET key value Set the value of the specified key. |
| 2 | GET key Get the value of the specified key. |
| 3 | GETRANGE key start end Get a substring of the string value stored at the key. |
| 4 | GETSET key value Set the value of the given key to value and return the old value of the key. |
| 5 | GETBIT key offset Get the bit at the specified offset from the string value stored at the key. |
| 6 | MGET key1 [key2..] Get the values of all (one or more) given keys. |
| 7 | SETBIT key offset value Set or clear the bit at the specified offset of the string value stored at the key. |
| 8 | SETEX key seconds value Associate the value value with the key and set the expiration time of the key to seconds (in seconds). |
| 9 | SETNX key value Set the value of the key only if the key does not exist. |
| 10 | SETRANGE key offset value Overwrite the string value stored at the given key starting at offset offset with the value parameter. |
| 11 | STRLEN key Return the length of the string value stored at the key. |
| 12 | MSET key value [key value ...] Set one or more key-value pairs at the same time. |
| 13 | MSETNX key value [key value ...] Set one or more key-value pairs at the same time, if and only if all the given keys do not exist. |
| 14 | PSETEX key milliseconds value This command is similar to the SETEX command, but it sets the key's lifetime in milliseconds, rather than in seconds like the SETEX command. |
| 15 | INCR key Increment the numeric value stored at the key by one. |
| 16 | INCRBY key increment Add the given increment value to the value stored at the key. |
| 17 | INCRBYFLOAT key increment Add the given floating-point increment value to the value stored at the key. |
| 18 | DECR key Decrement the numeric value stored at the key by one. |
| 19 | DECRBY key decrement Subtract the given decrement value from the value stored at the key. |
| 20 | APPEND key value If the key already exists and is a string, the APPEND command appends the specified value to the end of the original value of the key. |
For more commands, please refer to:https://redis.io/commands
Other extensions