Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Redis String


May 16, 2021 Redis


Table of contents


Redis String

The relevant commands for the Redis string data type are used to manage the 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 commands, with the key w3ckey.


Redis string command

The following table lists commonly used redis string commands:

Serial number Commands and descriptions
1 SET key value
Set the value of the specified key
2 GET key
Gets the value of the specified key.
3 GETRANGE key start end
Returns sub-characters of string values in key
4 GETSET key value
Set the value of a given key to value and return the old value of the key.
5 GETBIT key offset
For the string value stored by key, get the bit on the specified offset.
6 MGET key1 [key2..]
Gets all (one or more) values for a given key.
7 SETBIT key offset value
Set or clear bits on a specified offset for the string value stored by key.
8 SETEX key seconds value
Associate the value value to key and set the key's expiration time to seconds.
9 SETNX key value
Set the value of key only if it does not exist.
10 SETRANGE key offset value
Overwrides the value of the string stored by a given key with the value parameter, starting with offset offset.
11 STRLEN key
Returns the length of the string value stored by 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, when and only if all given keys do not exist.
14 PSETEX key milliseconds value
This command is similar to the SETEX command, but it sets the lifetime of key in milliseconds instead of seconds, as the SETEX command does.
15 INCR key
Add one value to the number stored in key.
16 INCRBY key increment
Add the value stored by key to the given incremental value.
17 INCRBYFLOAT key increment
Add the value stored by key to the given floating-point increment.
18 DECR key
Reduce the value of the number stored in key by one.
19 DECRBY key decrement
The value stored by key minus the given decrement.
20 APPEND key value
If the key already exists and is a string, the APPEND command appends value to the end of the key's original value.

For more commands, please refer to: http://redis.readthedocs.org/en/latest/index.html