Install and use Redis under Ubuntu

1. Install redis Use the command sudo apt-get install redis-server
  whereis redis to view the installation location of redis
  Insert picture description here
  ps -aux | grep redis to view the process of redis service Run
Insert picture description here
  netstat -nlt | grep 6379 to view the status of the redis server according to the port number that redis is running, Before the port number is the IP that the redis service monitors (the default is only the local IP 127.0.0.1)
Insert picture description here
2.Start redis
  locally to start the redis-cli
  Insert picture description here
  remote connection (requires the local redis client to be installed) redis-cli -h host (remote ip) -p port (port number) -a password (password) The
  following example demonstrates how to connect to the redis service whose host is 127.0.0.1, port is 6379, and password is mypass.

$redis-cli -h 127.0.0.1 -p 6379 -a "mypass"
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> PING

PONG

3. Redis configuration
  config get * View all configuration parameters of redis
  Insert picture description here
  config get (name) View a certain configuration parameter of redis
  Insert picture description here
  config set (name) (value) Modify some configurations of redis (some configuration modifications do not support this operation, for example Modify bind)
  Operations that do not support client modifications need to modify the redis configuration file sudo vi /etc/redis/redis.conf
    For example: modify the configuration file redis.conf to configure remote access
       (1) Find bind 127.0.0.1 in the configuration file Its note #bind 127.0.0.1
       (2) Restart redis to
use 4.redis use
  Basic use:
    del key is used to delete the existing key
    keys pattern to view all keys that match the pattern,
      such as keys * View all keys
    exists key to see if the key is There is a
    type key. View the storage type of the key.
    rename key newkey. Modify the name of the key.
  Redis mainly contains 5 data types: String, Hash, List, Set, Sorted set)
  (1) String type main operation
    set key value Set the value for the specified key
    get key Get the value of the specified key
    getrange key start end Get the substring of the specified key value start <= string <= end
    mget key1 key2… Get all the given key values
    strlen key Return the length of the string
    value stored in the key append key value If the key already exists and is a string, append will append the specified value to the end of the original value of the key, otherwise add a new key with value
  (2) Hash type main operation
    hmset key field1 value1 field2 value2… Set multiple field-value (domain-value) pairs to the hash table key
    hmget key field1 field2… Get all the values ​​of a given field
    hdel key field1 field2… Delete one or more fields
    hexists key field View the hash table key , the specified field is present
    hget key field obtain the storage of the specified field in the hash table key value
    hset key field value will be in the field for the value key value
    key acquisition hgetall hash table key in all fields and values
    hkeys key to get all Kazakhstan The field
    hvals key in the Greek table key Get all the values ​​in the
    hash table hlen key Get the number of fields in the hash table key

(3) The main operation of the list type (list)
    lpush key value1 value2… insert one or more values ​​into the head of the list
    rpush key value1 value2… insert one or more values ​​into the end of the list
    lpop key remove and get the list First element
    rpop key Remove and get the last element of the list
    lindex key index Get the element in the list by index
    linsert key before | after pivot value Insert element value before or after the list element pivot
    llen key Get the length of the list
    lrange key start end Get elements in the specified range of the list
    lrem key count value Remove list elements
      Remarks:
        count> 0: Search from the head of the table to the end of the table, remove the elements equal to VALUE, the number is COUNT.
        count <0: Search from the end of the table to the head of the table, remove elements equal to VALUE, and the number is the absolute value of COUNT.
        count = 0: Remove all values ​​equal to VALUE in the table.
    lset key index value Set the value of the list element by index
    ltrim key start end Let the list retain the elements within the range start end, and delete other elements

(4) The main operation of the set type (set)
    sadd key member1 member2… Add one or more members to the set
    scar key Get the number of members of the set
    sdiff key1 key2 Get the difference of the set Return key1, key2 not, and The sequence is related to
    sinter key1 key2 Get the intersection of key1 and key2
    sismember key member Determine whether member is a member of key
    smembers key Return all members in
    key spop key Remove and return a random element in
    key srandmember key [count] Return one of key Or multiple random number count values ​​are set to return a random number
    srem key member1 member2… remove one or more members from the collection
    sscan key cursor match [pattern] [COUNT count] Iterate the elements in the collection
      Remarks:
        cursor scan start position 0 1 Etc.
        match pattern regular matching is used to filter the
        number of cout scans

(5) The main operation of the sorted set type
    zadd key score1 member1 score2 member2… Add one or more members to the sorted set, or update the score of an existing member
    zcard key Get the number of members of the sorted set
    zcount key min max Calculate the number of members of the specified interval score in the ordered set
    zrange key start end Return the members in the specified interval of the ordered set through the index interval
    zrank key member Return the index of the specified member in the ordered set
    zrem key member1 member2… Remove One or more members in the ordered set
    zrevrange key start end Returns the members in the specified range in the ordered set, through the index, the score is from the highest to the bottom
    zrevrank key member Returns the rank of the specified member in the ordered set, and the ordered set starts from the score Sort large to small
    zscore key member Return the score value of the members in the ordered set
    zscan key cursor [match pattern] [count] Iterate over the elements in the ordered set (including element members and element scores)
Very good tutorial https://www .runoob.com/redis/redis-pub-sub.html

Insert picture description here

Guess you like

Origin blog.csdn.net/BigData_Mining/article/details/107307098