Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis String

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 runoobkey redis

OK

redis 127.0.0.1:6379> GET runoobkey

"redis"

In the example above we used SET and GET command, key is runoobkey.


Redis String Commands

The table below lists the 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
Return a substring of the string value at 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
For the string value stored at key, get the bit at the specified offset.
6 MGET key1 [key2..]
Get the values of all (one or more) given keys.
7 SETBIT key offset value
For the string value stored at key, set or clear the bit at the specified offset.
8 SETEX key seconds value
Associate value with key and set the expiration of key to seconds.
9 SETNX key value
Set the value of key only if key does not exist.
10 SETRANGE key offset value
Overwrite the string value stored at the given key with value, starting at offset.
11 STRLEN key
Return the length of the string value stored at key.
12 MSET key value [key value ...]
Set one or more key-value pairs at once.
13 MSETNX key value [key value ...]
Set one or more key-value pairs, only if all given keys do not exist.
14 PSETEX key milliseconds value
This command is similar to SETEX, but it sets the time to live of key in milliseconds instead of seconds.
15 INCR key
Increment the numeric value stored at key by one.
16 INCRBY key increment
Add the given increment to the value stored at key.
17 INCRBYFLOAT key increment
Add the given floating-point increment to the value stored at key.
18 DECR key
Decrement the numeric value stored at key by one.
19 DECRBY key decrement
Subtract the given decrement from the value stored at key.
20 APPEND key value
If key already exists and is a string, the APPEND command appends the specified value to the end of the key's original value.

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