当前位置:网站首页>[redis] install redis in Ubuntu and the basic usage and configuration of redis

[redis] install redis in Ubuntu and the basic usage and configuration of redis

2022-06-22 01:03:00 sinat_ twenty-one million seven hundred and ninety-one thousand

 

Link to the original text :https://www.cnblogs.com/donghaonan/p/10403781.html

For the convenience of learning to view , Temporary record , Invasion and deletion

 

1. install redis Use command sudo apt-get install redis-server
  whereis redis see redis Installation position of
  ps -aux | grep redis see redis The process of the service runs
  netstat -nlt | grep 6379 according to redis View the running port number redis Server status , Port number preceded by redis Service Monitor IP( By default, it's local IP 127.0.0.1)
2. start-up redis
   Local boot redis-cli
   Remote connection ( Need to install locally redis client ) redis-cli -h host( long-range ip) -p port( Port number ) -a password( password )
3.redis Configuration of
  config get * see redis All configuration parameters of
  config get (name) see redis A configuration parameter
  config set (name) (value) modify redis Some of the configurations ( Some configuration modifications do not support this operation , For example, modify bind)
   Operations that do not support client modification need to be modified redis Configuration file for sudo vi /etc/redis/redis.conf
     for example : Modify the configuration file redis.conf Configure remote access
         (1) Look in the configuration file for bind 127.0.0.1 Annotate Change it to #bind 127.0.0.1
            (2) Restart redis that will do
4.redis Use
   Basic use :
    del key Used to delete existing key
    keys pattern View all that match the pattern key
       for example keys * View all key
    exists key see key Whether there is
    type key see key Storage type of
    rename key newkey modify key The name of
  redis It mainly includes 5 Data type string in (String)、 Hash (Hash)、 list (list)、 aggregate (Set)、 Ordered set (Sorted set)
  (1) character string (String) Type main operation
    set key value For a given key Set the value
    get key Get specified key Value
    getrange key start end Get specified key Value substring start <= String <= end
    mget key1 key2 ... Get all the given key value
    strlen key return key The length of the stored string value
    append key value If key Already exists and is a string ,append Specifies the value Append to the key It was worth the end , Otherwise, add a new key The value is value
  (2) Hash (Hash) The main operation of type
    hmset key field1 value1 field2 value2 ... Will be multiple field-value( Domain - value ) Set to hash table key in
    hmget key field1 field2 ... Get the value of all the given fields
    hdel key field1 field2 ... Delete one or more fields
    hexists key field Look at the hash table key in , Specifies whether the field exists
    hget key field Get the information stored in the hash table key The value of the specified field in
    hset key field value take key The field value in is set to value
    hgetall key Get hash table key All fields and values in
    hkeys key Get all hash tables key Middle field
    hvals key Get all values in hash table
    hlen key Get hash table key The number of fields in

  (3) List the type (list) The main operation of
    lpush key value1 value2 ... Insert one or more values into the list header
    rpush key value1 value2 ... Insert one or more values at the end of the list
    lpop key Remove and get the first element of the list
    rpop key Remove and get the last element of the list
    lindex key index Get the elements in the list by index
    linsert key before | after pivot value In the list element pivot Insert elements before or after value
    llen key Get list length
    lrange key start end Get the elements in the specified range of the list
    lrem key count value Remove list elements
       remarks :
        count > 0 : Search from header to footer , Remove and VALUE Equal elements , The number of COUNT .
        count < 0 : Search from the end of the table to the header , Remove and VALUE Equal elements , The number of COUNT The absolute value of .
        count = 0 : Remove all and from the table VALUE Equal value .
    lset key index value Set the value of the list element through the index
    ltrim key start end Let the list keep the interval start end Elements in scope , Delete other elements

  (4) Collection types (set) The main operation of
    sadd key member1 member2 ... Add one or more members to the collection
    scard key Get the number of members of the collection
    sdiff key1 key2 Get the difference set of the set return key1 There is , key2 Not found in , It is related to the sequence
    sinter key1 key2 obtain key1 and key2 Intersection
    sismember key member Judge member Whether it is key Member of the
    smembers key return key All the members of the
    spop key Remove and return key A random element in
    srandmember key [count] return key One or more random numbers in count Value setting returns a random number
    srem key member1 member2 ... Remove one or more members of the collection
    sscan key cursor match [pattern] [COUNT count] Iterate over the elements in the collection
       remarks :
        cursor Where the scan starts 0 1 etc.
        match pattern Regular matching is used for filtering
        cout Number of scans

  (5) Ordered set (sorted set) The main operation of type
    zadd key score1 member1 score2 member2 ... Add one or more members to an ordered collection , Or update scores of existing members
    zcard key Get the number of members of the ordered set
    zcount key min max Calculates the number of members of a specified interval fraction in an ordered set
    zrange key start end Return the members in the specified interval of the ordered set through the index interval
    zrank key member Returns the index of a specified member in an ordered collection
    zrem key member1 member2 ... Remove one or more members from an ordered set
    zrevrange key start end Returns the members of a specified interval in an ordered set , Through the index , Score from high to the end
    zrevrank key member Returns the rank of a specified member in an ordered set , Ordered sets are arranged in order of the fraction
    zscore key member Returns the member score value in an ordered set
    zscan key cursor [match pattern] [count] Iterate over elements in an ordered set ( Include element members and element scores )

原网站

版权声明
本文为[sinat_ twenty-one million seven hundred and ninety-one thousand]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206212352277040.html