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
1SET key value
Set the value of the specified key.
2GET key
Get the value of the specified key.
3GETRANGE key start end
Get a substring of the string value stored at 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 from the string value stored at the key.
6MGET key1 [key2..]
Get the values of all (one or more) given keys.
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
Overwrite the string value stored at the given key starting at offset offset with the value parameter.
11STRLEN key
Return the length of the string value stored at the key.
12MSET key value [key value ...]
Set one or more key-value pairs at the same time.
13MSETNX 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.
14PSETEX 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.
15INCR key
Increment the numeric value stored at the key by one.
16INCRBY key increment
Add the given increment value to the value stored at the key.
17INCRBYFLOAT key increment
Add the given floating-point increment value to the value stored at the key.
18DECR key
Decrement the numeric value stored at the key by one.
19DECRBY key decrement
Subtract the given decrement value from the value stored at the key.
20APPEND 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