The string data type common redis Methods

redis string (string) [] need to know

Feature

  • A key data can store 512MB
  • The string type is binary safe and can store any data, such as jpg image or serialized objects

redis string data type for managing the commands redis string value, the basic syntax is as follows:

grammar

  1. Provided the specified key value == == set key values

    127.0.0.1:6379> set name panlifu
    OK
    127.0.0.1:6379> get name 
    "panlifu"
  2. == get key == get the value of a specified key

    127.0.0.1:6379> set name panlifu
    OK
    127.0.0.1:6379> get name 
    "panlifu"
  3. getrange key start end return key character sub-string, the function similar to the slice in the python, except that redis Gu Gu head tail

    127.0.0.1:6379> set name panlifu
    OK
    127.0.0.1:6379> get name 
    "panlifu"
    127.0.0.1:6379> GETRANGE name 0 3
    "panl"
  4. getset key value is set to a given value of the key value, and returns the key of the old value (old value)

    127.0.0.1:6379> set name panlifu
    OK
    127.0.0.1:6379> get name 
    "panlifu"
    127.0.0.1:6379> GETRANGE name 0 3
    "panl"
    127.0.0.1:6379> GETSET name lt
    "panlifu"
    127.0.0.1:6379> get name
    "lt"
  5. getbit key offset value of the key string stored, obtaining bits (bit) on the specified offset?

  6. setbit key offset value to the key value stored in a string, set or clear the bits (bit) on the specified offset?

  7. == mget key1 [key2 ...] == accessories (s) of the given key value

    127.0.0.1:6379> get name
    "panlifu"
    127.0.0.1:6379> set age 24
    OK
    127.0.0.1:6379> get age
    "24"
    127.0.0.1:6379> get age name
    (error) ERR wrong number of arguments for 'get' command
    127.0.0.1:6379> mget name age
    1) "panlifu"
    2) "24"
    127.0.0.1:6379> 
  8. == setex key secondes value == value associated with the value of the key, and set the key expiration time secondes (in seconds)

    # 第一种方法
    127.0.0.1:6379> setex name 5 "panlifu"
    OK
    127.0.0.1:6379> get name
    "panlifu"
    127.0.0.1:6379> get name
    (nil)
    
    # 第二种方法
    127.0.0.1:6379> set name panlifu ex 6
    OK
    127.0.0.1:6379> get name
    "panlifu"
    127.0.0.1:6379> get name
    "panlifu"
    127.0.0.1:6379> get name
    "panlifu"
    127.0.0.1:6379> get name
    (nil)
  9. == setnx key value == key value is only set when the key is not present

    127.0.0.1:6379> get name
    (nil)
    127.0.0.1:6379> setnx name panlifu
    (integer) 1
    127.0.0.1:6379> get name 
    "panlifu"
    127.0.0.1:6379> get name 
    "panlifu"
    127.0.0.1:6379> setnx name lt
    (integer) 0
    127.0.0.1:6379> get name 
    "panlifu"
  10. SetRange key offset value set by the value parameter string written overlying the stored key value, offset offset from the start

    127.0.0.1:6379> set name "hello world"
    OK
    127.0.0.1:6379> get name
    "hello world"
    127.0.0.1:6379> SETRANGE name 6 "redis"
    (integer) 11
    127.0.0.1:6379> get name
    "hello redis"
    
  11. mset key value [key value] and set to one or more key -value

    127.0.0.1:6379> mset name panlifu age 18
    OK
    127.0.0.1:6379> get name
    "panlifu"
    127.0.0.1:6379> get age
    "18"
    
  12. msetnx key value [key value] and set one or more key-value pairs, if and only if all the given key does not exist

    127.0.0.1:6379> msetnx sex boy height 120
    (integer) 1
    127.0.0.1:6379> get sex
    "boy"
    127.0.0.1:6379> get height
    "120"
    127.0.0.1:6379> msetnx name lt age 17
    (integer) 0
    127.0.0.1:6379> get name
    "panlifu"
    127.0.0.1:6379> get age
    "18"
    

    == Summary: m has a front generally refers to the key may be provided a plurality of pairs. Usually after a key with nx indicates only when the key does not exist, to set the key. ==

  13. strlen key returns the length of the string stored key value

    127.0.0.1:6379> get name
    "panlifu"
    127.0.0.1:6379> strlen name
    (integer) 7
  14. psetex key milliseconds value SETEX command and this command is similar, but in milliseconds lifetime for key is provided, rather than as SETEX command, in seconds

    127.0.0.1:6379> psetex name 1000 hehe
    OK
    127.0.0.1:6379> get name
    "hehe"
    127.0.0.1:6379> get name
    (nil)

    == summarize: When the end key to ex, generally represents the key expiration time, in seconds. When the key front and behind a p-ex, it said provided key expiration time in milliseconds ==

  15. incr the key value stored in the key number is incremented

    127.0.0.1:6379> set age 19
    OK
    127.0.0.1:6379> get age
    "19"
    127.0.0.1:6379> incr age
    (integer) 20
    127.0.0.1:6379> incr age
    (integer) 21
    127.0.0.1:6379> get age
    "21"
    127.0.0.1:6379> set age "19"
    OK
    127.0.0.1:6379> get age
    "19"
    127.0.0.1:6379> incr age
    (integer) 20
    127.0.0.1:6379> incr age
    (integer) 21
    127.0.0.1:6379> get age
    "21"
    127.0.0.1:6379> incr age
    (integer) 22
    127.0.0.1:6379> get age
    "22"
    127.0.0.1:6379> type age
    string

    == Summary: Data string data types, value types are string data type. As long string all numbers, you can use incr key ==

  16. incrby key increment the key value stored in the floating-point plus the increment value given

    127.0.0.1:6379> get age
    "27"
    127.0.0.1:6379> incrby age 3
    (integer) 30
    127.0.0.1:6379> get age
    "30"
  17. incrbyfloat key increment the key the stored value plus the increment value given floating point (increment).

    127.0.0.1:6379> get age
    "30"
    127.0.0.1:6379> incrbyfloat age 1.5
    "31.5"
    127.0.0.1:6379> get age
    "31.5"
  18. decrby key decrement key value stored by the given decrement value (Decrement)

    127.0.0.1:6379> incrbyfloat age -1.5
    "30"
    127.0.0.1:6379> decrby age 5
    (integer) 25
    127.0.0.1:6379> get age
    "25"
  19. DECR key number stored in the key value minus one.

  20. If the append key value is a key string already exists, APPEND command specified key value appended to the original value (value) of.

    127.0.0.1:6379> get age
    "25"
    127.0.0.1:6379> append age hehe
    (integer) 6
    127.0.0.1:6379> get age
    "25hehe"
    

Guess you like

Origin www.cnblogs.com/plf-Jack/p/11025112.html