当前位置:网站首页>Redis command string

Redis command string

2022-06-25 18:14:00 [email protected]

1. set

set key value Set the corresponding value for a string key
 Insert picture description here

Twice use set, hinder set The set value will overwrite the previously set value

With options set:

  1. NX:SET The command will only perform the setting operation when the key has no value
     Insert picture description here
  2. XX: SET The command only performs the setting operation when the key already has a value

 Insert picture description here

2. get

get key Get the value of the specified string key from the database
 Insert picture description here

3. getset

getset key new_value: First, get the current value of the string key , Then set a new value for the key , Finally, the old value obtained before is returned to the user
 Insert picture description here

4. mset

mset key1 value1 key2 value2...:MSET The command can set values for multiple string keys at once
 Insert picture description here
Continuous multiple use mset, The new value overwrites the old value

5. mget

mget kay1 key2...:MGET Accept one or more string keys as arguments , And return the values of these string keys
 Insert picture description here
If mget To a nonexistent key, return nil

6. msetnx

msetxx key1 value1 key2 value2...: MSETNX The key is set only when none of the given keys exist
 Insert picture description here  Insert picture description here

7. strlen

strlen(key): Get the byte length of the value stored in the string key
 Insert picture description here
 Insert picture description here

8. String index

 Insert picture description here

8.1 getrange

getrange key start end: Get string key[start,end] Left closed right closed interval
 Insert picture description here

8.2 setrange

set key index new_content: Remove the value of the string key from the index index Replace the beginning with the specified new content
 Insert picture description here
When the new content given by the user is longer than the replaced content ,SETRANGE The command will automatically expand the modified string value , To ensure that new content can be written smoothly
 Insert picture description here

9. append

append key suffix Appends the given content to the end of the existing value of the string key
 Insert picture description here  Insert picture description here

10. incrby/decrby

incrby key1 increment Integer value plus the specified Integer increment
 Insert picture description here
decrby key1 increment Integer value minus the specified Integer increment

 Insert picture description here

10.1 Type restrictions

 Insert picture description here

  1. key Cannot be of string type ,incrment Empathy
  2. key It can't be a floating-point number ,incrment Empathy
  3. key Can't be more than 64 An integer ,incrment Empathy

10.2 Handle nonexistent keys

 Insert picture description here

11. incr/decr

incr key Integer value plus 1
decr key Integer value minus 1
 Insert picture description here

12. incrbyfloat

incrbyfloat key increment: Add a floating-point increment to the numeric value stored in the string key , And return the numeric value of the key after performing the addition operation as the return of the command
 Insert picture description here
If you want to subtract, you will increment Set to negative

Be careful :

  1. INCRBYFLOAT The command can be used for both floating-point values , It can also be used for integer values
  2. INCRBYFLOAT The increment of the command can be either a floating point number , It can also be an integer
  3. When INCRBYFLOAT When the execution result of the command can be expressed as an integer , The execution result of the command will be stored as an integer
原网站

版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190532337480.html