In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "what are the five basic types of Redis", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what are the five basic types of Redis" article.
Redis traditional 5. The application of big data type
Landing application of redis traditional 5 big data type
Redis introduction:
Redis is an open source (BSD licensed), in-memory data structure storage system that can be used as database, cache, and messaging middleware. It supports many types of data structures, such as string (strings), hash (hashes), list (lists), set (sets), ordered set (sorted sets)] and range query, bitmaps, hyperloglogs and geospatial (geospatial) index radius query. Redis has built-in replication (replication), LUA script (Lua scripting), LRU driven event (LRU eviction), transaction (transactions) and different levels of disk persistence (persistence), and provides high availability (high availability) through Redis Sentinel (Sentinel) and automatic partitioning (Cluster).
Note: the redis command is not case-sensitive, while key is case-sensitive
Query command help:
Help @ type noun
Example:
String string type
Most commonly used
Set key vuue
Getkey
Set / get multiple key values at the same time
MSET key value [key value...]
MGET key [key,]
Numerical increase or decrease
Incremental digital incr key
Increase the specified integer incrby key increment
Decreasing value decr key
Reduce the specified integer decrby key decrement
Get character length
STRLEN key
Distributed lock
Setnx key value
Set key value [EX seconds] [PX milliseconds] [NX | XX]
EX: how many seconds before key expires
PX: how many milliseconds since key expires
NX: create a key. NX when key does not exist. The effect is equivalent to that of setnx
XX: overrides key when key exists
Application scene
Item number and order number are generated by INCR command
Do you like to like the article?
Readings: as long as you click on the rest address, directly use the incr key command to add a number 1 to complete the recording of the number.
Command practice
Hash hash type
And Java data structure mapping
Map
Set one field value at a time
HSET key field value
Get one field value at a time
HGET key field
Set multiple field values at a time
HMSET key field value [fild value...]
Get more than one field value at a time
HMGET key field [field...]
Get all field values
Hgetall key
Get all the quantities in a key
Hlen
Delete a key
Hdel
Command demonstration
Application scenario
In the early days of shopping carts, small and medium-sized factories can now use them.
New products-- > hset shopcar:uid1024 334488 1
New products-- > hset shopcar:uid2014 334477 1
Increase the number of goods-- > hincrby shopcar:uid1024 334477 1
Total number of goods-- > hlen shopcar:uid1024
Select all-- > hgetall shopcar:uid1024
List list type
Add an element to the left of the list
Lpush key value [value...]
Add an element to the right of the list
Rpush key value [value...]
View list
Lrange key start stop
Gets the number of elements in the list
Llen key
Command u
Application scenario
Wechat articles subscribe to official account
1. [xxbao] and [xxbao] published articles 11 and 22 respectively
2. The author follows both of them, and whenever they post a new article, they will push it to my list.
Lpush likearticle: uid1024 11 22
3. Check all the author's own Subscription account articles, which are similar to pagination. The following 0-10 shows 10 lrange likearticle:uid1024 0 10 at a time.
Set does not repeat list types
Add element
Sadd key member [member...]
Delete element
Srem key member [member...]
Get all the elements of the collection
Smembers key
Determine whether the element is in the collection
Sismember key member
Gets the number of elements in the collection
Scard key
An element pops up randomly from the collection and is not deleted
Srandmember key [digital]
Randomly pop up an element from the collection, delete one by one
Spop key [digital]
Set operation
Subtraction operation A-B of a set
A collection of elements that belong to A but not to B.
Sdiff key [key...]
The intersection element of a set is A ^ B
It belongs to the elements jointly owned by An and B.
Simter key [key...]
Union operation A v B of a set
A merged collection of elements that belong to An or B
Sunion key [key...]
Application scene
Wechat lucky draw Mini Program
1. User id, participate immediately, sadd key user id
2. Show how many people have participated and currently 67231 people have participated, scard key
3. Draw lottery (randomly select N winners from set)
Srandmember key 2 draws 2 people randomly, the element will not be deleted.
Spop key 3 driver draw 3 people, the element will be deleted.
Like on Wechat moments.
1. Add likes; sadd pub:msgid likes users id1 likes users id2
2. Cancel likes; srem pub:msgid likes users id
3. Show smembers pub:msgid of all users who have been liked.
4. Statistics on the number of like users, which is the common red number scard pub:msgid to be liked.
5. Judge whether a friend likes the building master too much. Sismember pub:msgid user id
Weibo friends pay attention to social relationships.
People of common concern
Sadd s1 1 2 3 4
Sadd s2 2 3 6 8
Sinter s1 s2
Common concern: I go to someone's Weibo and immediately get someone who shares their attention.
The people I follow, also follow him (we all have the same hobbies)
I followed Huawei Yu Chengdong, and Yu Chengdong also followed Zhang Zhaozhi. Yu and I have common hobbies.
Sadd s1 1 2 3 4 5
Sadd s2 3 4 5 6 7
Sismember s1 3
Sismember s2 3
QQ tweets people you may know
Sadd s1 1 2 3 4 5
Sadd s2 3 4 5 6 7
/ / Common Friends
Sinter s1 s2
/ / difference set
Sdiff s1 s2
Sdiff s2 s1
Zset ordered set
Common command
1. Add an element and its score to the ordered collection
2. Add elements
ZADD key score member [score member...]
3. Return all elements indexed from strat to stop in the order in which the element scores arrive.
Zrange key start stop [WITHSORES]
4. Get the score of the element
Zscore key member [member...]
5. Delete elements
Zrem key member [member...]
6. Get the elements in the specified score range
Zrangebyscore key min max [WITHSCORES] [LIMIT offset count]
7. Increase the score of an element
Zincrby key increment member
8. Get the number of elements in the collection
Zcard key
9. Get the number of elements within the specified score range
Zcount key min max
10. Delete elements according to the ranking range
Zremrangebyrank key start stop
11. Get the ranking of elements
Zrank key member from small to big
From big to small zrevrank key member
Application scenario
1. More merchandise sales to sort the goods and display them.
Idea: define the ranking of commodity sales (sorted set collection). Key is goods:sellsort and the score is the number of goods sold.
The sales volume of item no. 1001 is 9, and that of item no. 1002 is 15 | zadd goods:sellsort 9 1001 15 1002
One customer bought two more items 1001. The item number is 1001 and increases by 2. | zincrby goods:sellsort 2 10001
Ask for the top 10 merchandise sales zrange goods:sellsort 0 10 withscores
2. Hot search on Douyin
1. Click on the video
ZINCRBY hotavi:20220203 1,800
ZINCRBY hotavi:20220203 15 eight hundred two Mulan
2. Top 10 items on the day of display
Zrevrange hotavi:20220203 0 9 withscores
The above is the content of this article on "what are the five basic types of Redis". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.