当前位置:网站首页>Redis related-01

Redis related-01

2022-06-25 03:44:00 legend_ go

Redis Basic relevance -01

One 、 What is? Redis?

Official description :

Redis It's open source (BSD The license ) Of , Data structure storage system in memory , It can be used as a database 、 Caching and message middleware . It supports multiple types of data structures , Such as character string (strings), hash (hashes), list (lists), aggregate (sets), Ordered set (sorted sets) And scope query , bitmaps, hyperloglogs and Geographical space (geospatial) Index radius query . Redis Built in Copy (replication),LUA Script (Lua scripting), LRU Driving events (LRU eviction), Business (transactions) And different levels of Disk persistence (persistence), And pass Redis sentry (Sentinel) And automatic Partition (Cluster) Provide high availability (high availability).

Personal understanding :

  • It can be used as a database
  • Used as a cache , Finally, it is persisted to the database
  • Message oriented middleware implements the subscription and publication of messages
  • Very fast read speed

Two 、Linux Lower installation Redis

1、 stay Redis Download the compressed package on the official website

Download link

 Insert picture description here

2、 utilize XFTP The tool is uploaded to a folder on the remote server

Execute the following command :

# Unzip the file 
tar -zxvf redis-6.2.6.tar.gz

# Enter the unzipped folder 
cd redis-6.2.6

# compile 
make
make install

# Get into src Folder 
cd src

# start-up Redis
./redis-server ../redis.conf

# start-up Redis client 
./redis-cli

Deployment success

3、 ... and 、Redis Common commands and basic data types

1、Redis key

1DEL key This command is used in key Delete... When it exists key.
2DUMP key Serialization given key , And return the serialized value .
3EXISTS key Check the given key Whether there is .
4EXPIRE key seconds For a given key Set expiration time , In seconds .
5EXPIREAT key timestamp EXPIREAT Function and EXPIRE similar , All for key Set expiration time . Difference is that EXPIREAT The time parameter accepted by the command is UNIX Time stamp (unix timestamp).
6PEXPIRE key milliseconds Set up key In milliseconds .
7PEXPIREAT key milliseconds-timestamp Set up key Time stamp of expiration time (unix timestamp) In milliseconds
8KEYS pattern Find all that match the given pattern ( pattern) Of key .
9MOVE key db Will be the current database of key Move to a given database db among .
10PERSIST key remove key The expiration time of ,key Will last .
11PTTL key Returns... In milliseconds key The remaining expiration time of .
12TTL key In seconds , Return to a given key The remaining lifetime of (TTL, time to live).
13RANDOMKEY Returns a random... From the current database key .
14RENAME key newkey modify key The name of
15RENAMENX key newkey Only when the newkey When there is no , take key Renamed as newkey .
16[SCAN cursor MATCH pattern] [COUNT count] Iterate the database keys in the database .
17TYPE key return key The type of value stored .

2、String type

1SET key value Set the specified key Value
2GET key Get specified key Value .
3GETRANGE key start end return key The child character of the string value in
4GETSET key value Will be given key The value of the set value , And back to key The old value (old value).
5GETBIT key offset Yes key String value stored , Gets the bit on the specified offset (bit).
6[MGET key1 key2…] Get all ( One or more ) Given key Value .
7SETBIT key offset value Yes key String value stored , Sets or clears the bit on the specified offset (bit).
8SETEX key seconds value Will value value Related to key , And will key The expiration time of is set to seconds ( In seconds ).
9SETNX key value Only in key Set when not present key Value .
10SETRANGE key offset value use value Parameter override given key String value stored , From the offset offset Start .
11STRLEN key return key The length of the stored string value .
12[MSET key value key value …] Set one or more... At the same time key-value Yes .
13[MSETNX key value key value …] Set one or more... At the same time key-value Yes , If and only if all given key It doesn't exist .
14PSETEX key milliseconds value This command and SETEX Command similar , But it's set in milliseconds key Survival time , Not like it SETEX Order that , In seconds .
15INCR key take key The value of the number stored in is increased by one .
16INCRBY key increment take key The stored value plus the given increment value (increment) .
17INCRBYFLOAT key increment take key The stored value plus the given floating-point delta value (increment) .
18DECR key take key Subtract one from the number stored in .
19DECRBY key decrement key The stored value minus the given decrement value (decrement) .
20APPEND key value If key Already exists and is a string , APPEND The order will specify value Append to the key Original value (value) At the end of .

3、List type

1BLPOP key1 key2 ] timeout Move out and get the first element of the list , If there are no elements in the list, it will block the list until the wait timeout or pop-up elements are found .
2BRPOP key1 key2 ] timeout Move out and get the last element of the list , If there are no elements in the list, it will block the list until the wait timeout or pop-up elements are found .
3BRPOPLPUSH source destination timeout Pop up a value... From the list , Insert the pop-up element into another list and return it ; If there are no elements in the list, it will block the list until the wait timeout or pop-up elements are found .
4LINDEX key index Get the elements in the list by index
5LINSERT key BEFORE|AFTER pivot value Insert an element before or after a list element
6LLEN key Get list length
7LPOP key Move out and get the first element of the list
8[LPUSH key value1 value2] Insert one or more values into the list header
9LPUSHX key value Insert a value into the existing list header
10LRANGE key start stop Get the elements in the specified range of the list
11LREM key count value Remove list elements
12LSET key index value Set the value of the list element through the index
13LTRIM key start stop Trim a list (trim), That is to say , Let the list keep only the elements in the specified range , Elements that are not in the specified range will be removed .
14RPOP key Remove the last element of the list , The return value is the removed element .
15RPOPLPUSH source destination Remove the last element of the list , And add the element to another list and return
16[RPUSH key value1 value2] Add one or more values... To the list
17RPUSHX key value Add value to existing list

4、Set type

1SADD key member1 member2] Add one or more members to the collection
2SCARD key Get the number of members of the collection
3[SDIFF key1 key2] Returns the difference between the first set and the others .
4[SDIFFSTORE destination key1 key2] Returns the difference set of a given set and stores it in destination in
5[SINTER key1 key2] Returns the intersection of a given set
6[SINTERSTORE destination key1 key2] Returns the intersection of a given set and stores it in destination in
7SISMEMBER key member Judge member Is the element a collection key Members of
8SMEMBERS key Returns all members of the collection
9SMOVE source destination member take member Elements from source The assembly moves to destination aggregate
10SPOP key Remove and return a random element from the collection
11[SRANDMEMBER key count] Returns one or more random numbers in a set
12[SREM key member1 member2] Remove one or more members of the collection
13[SUNION key1 key2] Returns the union of all given sets
14[SUNIONSTORE destination key1 key2] The union of all given sets is stored in destination Collection
15[SSCAN key cursor MATCH pattern] [COUNT count] Iterate over the elements in the collection

5、Hash type

1[HDEL key field1 field2] Delete one or more hash table fields
2HEXISTS key field Look at the hash table key in , Whether the specified field exists .
3HGET key field Gets the value of the specified field stored in the hash table .
4HGETALL key Gets the specified in the hash table key All fields and values of
5HINCRBY key field increment Hash table key The integer value of the specified field in plus the increment increment .
6HINCRBYFLOAT key field increment Hash table key The floating-point value of the specified field in plus the increment increment .
7HKEYS key Get all the fields in the hash table
8HLEN key Get the number of fields in the hash table
9[HMGET key field1 field2] Get the value of all the given fields
10[HMSET key field1 value1 field2 value2 ] There will be more than one field-value ( Domain - value ) Set to hash table key in .
11HSET key field value Hash table key In the field field The value of the set value .
12HSETNX key field value Only in the fields field When there is no , Set the value of the hash table field .
13HVALS key Get all values in hash table .
14[HSCAN key cursor MATCH pattern] [COUNT count] Iterate over the key value pairs in the hash table .

6、 Ordered set ZSet

1[ZADD key score1 member1 score2 member2] Add one or more members... To an ordered collection , Or update scores of existing members
2ZCARD key Get the number of members of the ordered set
3ZCOUNT key min max Calculates the number of members of a specified interval fraction in an ordered set
4ZINCRBY key increment member Add the increment... To the score of the specified member in the ordered set increment
5[ZINTERSTORE destination numkeys key key …] Calculates the intersection of a given ordered set or sets and stores the result set in a new ordered set destination in
6ZLEXCOUNT key min max Computes the number of members in the specified dictionary interval in an ordered collection
7[ZRANGE key start stop WITHSCORES] Return the members in the specified interval of the ordered set through the index interval
8[ZRANGEBYLEX key min max LIMIT offset count] Returns the members of an ordered set through a dictionary interval
9[ZRANGEBYSCORE key min max WITHSCORES] [LIMIT] Returns the members of an ordered set in a specified interval through scores
10ZRANK key member Returns the index of a specified member in an ordered collection
11[ZREM key member member …] Remove one or more members of an ordered collection
12ZREMRANGEBYLEX key min max Remove all members of a given dictionary interval from an ordered set
13ZREMRANGEBYRANK key start stop Remove all members of a given rank range from an ordered set
14ZREMRANGEBYSCORE key min max Remove all members of a given fraction interval from an ordered set
15[ZREVRANGE key start stop WITHSCORES] Returns the members of a specified interval in an ordered set , Through the index , Scores go from high to low
16[ZREVRANGEBYSCORE key max min WITHSCORES] Returns the members of the specified score range in an ordered set , Rank scores from high to low
17ZREVRANK key member Returns the rank of a specified member in an ordered set , Members of an ordered set are decremented by fractions ( From big to small ) Sort
18ZSCORE key member Back to the ordered set , The score of a member
19[ZUNIONSTORE destination numkeys key key …] Computes the union of a given ordered set or sets , And store it in the new key in
20[ZSCAN key cursor MATCH pattern] [COUNT count] Iterate over elements in an ordered set ( Include element members and element scores )

Four 、 Three special types

  • Geospatial
  • Hyperloglog
  • Bitmap

1、Geospatial

  • GEOADD
  • GEODIST
  • GEORADIUS
  • GEOHASH
  • GEOPOS
  • GEORADIUSBYMMBER

Application scenarios : The man near the 、 Straight line distance, etc

2、Hyperloglog

1[PFADD key element element …] Add specified elements to HyperLogLog in .
2[PFCOUNT key key …] Return to a given HyperLogLog The base estimate of .
3[PFMERGE destkey sourcekey sourcekey …] Will be multiple HyperLogLog Merge into one HyperLogLog

Application scenarios : Website UV(User View) User access , Available cardinality statistics

3、Bitmap

  • SETBIT

  • GETBIT

Application scenarios : User clocks in

Related articles :

  • Redis-01
    • What is? Redis
    • stay Linux Lower installation Redis
    • Redis Common commands and basic data types
    • Three special types
  • Redis-02
    • Redis Implement basic transaction operations
    • Redis Achieve optimistic lock
    • adopt Jedis operation Redis
      • adopt Jedis Understand the business
    • SpringBoot Integrate Redis
    • Customize RedisTemplate
  • Redis-03
    • Redis Configuration file details
    • Persistence ——RDB operation
    • Persistence ——AOF operation
    • Redis Subscription Publishing
    • Redis Cluster environment construction
    • Master slave copy
    • Manually configure the host during downtime
    • Sentinel mode
    • Cache penetration and avalanche

Reference link :

Redis note

【 Madness theory Java】Redis The latest super detailed version of the tutorial is easy to understand

原网站

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