Redisstring type
One, view the command of type string
Second, the operation string example
One, view the command of type string
1. Open the Redis client and enter Help
127.0.0.1:6379>help
redis-cli2.8.19
Type: ' Help @<group> ' to get a list of commands in <group>
"Help <command>" for Helpon <command>
"Help <tab>" to get a listof possible Help topics
"Quit" to exit
Note: help is an aid command,
2. Enter [email protected]
127.0.0.1:6379>help @string
APPEND Key value
Summary:append a value to a key
since:2.0.0
Bitcount key [start] [end]
Summary:count set bits in a string
since:2.6.0
Bitop operation Destkey Key [key ...]
Summary:perform Bitwise Operations Betweenstrings
since:2.6.0
........
Note: because space is too large, omit some.
second, the operation string example
1. String Type command description
Command name |
Description |
Format |
Set |
Associates a string value to a key. If key already holds another value, the set will overwrite the old value, ignoring the type |
Set key value |
Get |
Returns the string value associated with the key. Returns the special value nil if key does not exist |
Get key |
Setnx |
Set the value of key to value when and only if key does not exist. If the given key already exists, then SETNX does not do any action |
Setnx Key value |
Setex |
Associates a value of values to a key and sets the lifetime of the key to seconds (in seconds). |
Setex Key seconds value |
SetRange |
Overwrite (Overwrite) The string value stored by the given key with the value parameter, starting at offset offsets. Non-existent key treated as a blank string |
SetRange Key Offset value |
Mset |
Set one or more key-value pairs at the same time. When a key with the same name is found, Mset overwrites the old value with the new value |
Mset key value [key value ...] |
Mget |
Returns the string value associated with multiple keys. Returns the special value nil if key does not exist |
Mget key1 Key2 ... |
Append |
If the key already exists and is a string, the append command appends value to the original value of the key. If key does not exist, append simply sets the given key to value, just as it does with set key value |
Append key value |
Msetnx |
Set one or more key-value pairs at the same time, when and only if key does not exist. Even if only one key already exists, MSETNX will reject the set operation of all incoming keys |
Msetnx key value [key value ...] |
GetRange |
Returns a substring of the string value in key, where the intercept range of the string is determined by the start and end two offsets (including start and end). A negative offset represents the last count from the string, 1 for the last character, 2 for the penultimate one, and so on |
GetRange Key Start end |
Getset |
Sets the value of the given key to value and returns the old value of key. An error is returned when key exists but is not a string type |
Getset Key value |
Strlen |
Returns the length of the string value stored by key. An error is returned when key is not stored as a string value |
Strlen Key |
Decr |
Subtract one of the numeric values stored in the key. If key does not exist, take 0 as the initial value of key and then perform the DECR operation |
DECR key |
Decrby |
Subtracts the value stored by the key minus the decrement decrement. If key does not exist, take 0 as the initial value of key and then perform the Decrby operation |
Decrby Key Decrement |
incr |
Add one of the numeric values stored in the key. If key does not exist, take 0 as the initial value of key and then perform the incr operation |
INCR key |
Incrby |
Add the value stored by the key to the increment increment. If key does not exist, take 0 as the initial value of key and then perform the Incrby operation |
Incrby Key Increment |
|
|
|
2. Single string manipulation
2.1. Set key to name, and its value is Xiaobei
127.0.0.1:6379> SetName Xiaobei
Ok
2.2. Get the value of key name
127.0.0.1:6379> Get Name
"Xiaobei"
2.3. Get the character length of key name
127.0.0.1:6379>strlen Name
(integer) 7
2.4. To key name, append character ' is good. '
127.0.0.1:6379>append name ' is good '
(integer) 15
127.0.0.1:6379>get Name
"Xiaobeiis Good"
2.5. Replace the good in key name with the great
127.0.0.1:6379>setrange name Great
(integer) 16
127.0.0.1:6379>get Name
"Xiaobeiis Great"
3. Set multiple characters in bulk
3.1. Set key to Name,age, respectively, and its value corresponds to xiaobei,24
127.0.0.1:6379>mset name Xiaobei Age 24
Ok
3.2. Get the value of key for name and age
127.0.0.1:6379>mget name Age
1) "Xiaobei"
2) "24"
4. Self-increment or self-reduction operation
4.1. Self-increment operation
127.0.0.1:6379>INCR C
(integer) 1
127.0.0.1:6379>get C
"1"
127.0.0.1:6379>INCR C
(integer) 2
127.0.0.1:6379>get C
"2"
4.2. Self-reduction operation
127.0.0.1:6379>DECR C
(integer) 1
127.0.0.1:6379>get C
"1"
127.0.0.1:6379>DECR C
(integer) 0
127.0.0.1:6379>get C
"0"
4.3. Press 10 for self-increment
127.0.0.1:6379>incrby C 10
(integer) 10
127.0.0.1:6379>get C
"10"
127.0.0.1:6379>incrby C 10
(integer) 20
127.0.0.1:6379>get C
"20"
4.4, press 10 for self-reduction
127.0.0.1:6379>decrby C 10
(integer) 10
127.0.0.1:6379>get C
"10"
127.0.0.1:6379>decrby C 10
(integer) 0
127.0.0.1:6379>get C
"0"
5. Common Mistakes
5.1, self-increment or decrement only for the numeric string of key or nonexistent key
127.0.0.1:6379>set name ' 1 '
Ok
127.0.0.1:6379>get Name
"1"
127.0.0.1:6379>INCR Name
(integer) 2
127.0.0.1:6379>set name ' Xiaobei '
Ok
127.0.0.1:6379>get Name
"Xiaobei"
127.0.0.1:6379>INCR Name
(Error) ERR value is not a integer or out of range
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Beckham _redis String Type learning