Introduction to Redis (2)
This article will focus on getting started with five basic data types
The articles
- Redis6 – Introduction (Part 1)
Redis Visual Management tool – Redis Desktop Manager
Link: pan.baidu.com/s/1xom9Fbql… Extraction code: 6666
Follow the steps to connect to redis remote server Redis requires port firewall
Chinese and English can be switched in setting
After the connection is successful, you can see a total of 16 databases. The default operation is db0
Redis five data types – string
String is the most common and basic type, and many Java objects can also be stored as JSON strings
Common commands
Use./redis-cli –raw
MSET key value [key value….] MGET key [key…] INCR Key increases values INCRBY key InrCement Increases a specified integer DECR key decreases a specified integer STRLEN key decrement decreases the length of a string acquired by a specified integer
Distributed lock related content will be in the subsequent setnx emphasis on key value set key value [EX seconds] [PX milliseconds] [NX | XX]
Application scenarios
- Stores basic user information
- Incr Key – based click count store for articles
- Douyin live unlimited likes and so on
- .
Redis five data types – hash
HMSET key field value [field value…] HMGET key field [field….] hgetall key hlen hdel
Redis five data types – list
A double-ended linked list structure, the capacity is 2 32 power minus 1 element, about more than 4 billion, the main function has push/ POP, generally used in stack, queue, message queue and other scenarios. Because it is a double-ended linked list structure, the operation on both ends is fast, and the operation on the middle data is slow
Common commands
LPUSH key value [value …] Add element RPUSH key value to left side of list [value….] Add elements to the right of the list LRANGE key Start stop View the list LLEN key Obtain the number of elements in the list
Application scenarios
- Wechat official account subscription message
- Product Review list
Redis five data types – set
A Redis Set is an unordered arrangement of strings.
Common commands
SADD key member [member …] SREM key member [member…] SCARD key retrits the total number of elements in the set. SRANDMEMBER key [number] Pops an element randomly from the set. Element does not remove SPOP key [number] randomly pop up an element from the collection, remove a SDIFF key [key…] A set of elements belonging to A but not to B. The set of elements jointly owned by A and B. The set of merged elements that belong to A or B
Application scenarios
- Draw small programs sadd, scard,sismember, spop
- Friends marks sadd, srem, smembers, sismember, etc
- Mutual friend Sinter
- Someone you might know, Sunion
Redis five data types – zset
Zse consists of a unique, non-repeating string element.
However, while elements inside the collated set are not sorted, each element in the collated set is associated with a floating point value, called a score.
Common commands
ZADD key score member [score member …] Add element ZRANGE key start stop [WITHSCORES] return index ZSCORE key member ZREM key member ZRANGE key start stop [WITHSCORES [member …] ZINCRBY key Increment Member ZRANGEBYSCORE key min Max [WITHSCORES] [LIMIT offset count] ZINCRBY key increment Member ZCARD key obtains the number of elements in the set ZCOUNT key min Max Obtains the number of elements in the specified score range ZREMRANGEBYRANK key start stop Deletes elements according to the ranking range ZRANK key member ranks from small to large ZREVRANK Key Member rank from large to small
Application scenarios
- Shake out
- Display items in order of sales
- .
conclusion
These are the common commands and application scenarios for the five common data types, and we’ll get to the code later