In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what the application scenario of Redis is, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. Introduction to Redis
Redis is an open source key- value single-threaded database that supports string, list, set, zset, and hash type data.
Default port: 6379
Default number of databases: 16
Second, advantages:
The 1.nosql database has no association, the data structure is simple, and it is easy to expand the table.
The reading speed of 2.nosql is fast, and the processing speed is faster than that of big data.
3. Applicable scenarios:
1. Read and write data with high concurrency
two。 Reading and writing of massive data
Data that requires high scalability
4. Discomfort scenarios:
1. Transaction support is required (non-relational database)
two。 Structured query storage based on sql, complex relationship
5. Application scenarios
The following authors are Redis author @ antirez, who describes some suitable application scenarios for Redis. NoSQLFan is briefly listed here for you to have a look at:
1. The operation of taking the latest N pieces of data
For example, typically fetching the latest articles from your website, we can put the ID of the latest 5000 comments in the List collection of Redis and retrieve the parts beyond the collection from the database in the following way
Use the LPUSH latest.comments command to insert data into the list collection
After inserting, use the LTRIM latest.comments 0 5000 command to save only the last 5000 ID forever.
Then we can use the following logic (pseudo code) when we get a comment on a page on the client side.
FUNCTION get_latest_comments (start,num_items): id_list = redis.lrange ("latest.comments", start,start+num_items-1) IF id_list.length < num_items id_list = SQL_DB ("SELECT... ORDER BY time LIMIT...") END RETURN id_listEND
If you have different screening dimensions, such as the latest N items of a category, then you can create another List according to this category, and only ID, Redis is very efficient.
two。 Ranking application, take TOP N operation
The difference between this requirement and the above requirements is that the previous operation takes time as the weight, and this is based on a certain condition, such as sorting by the number of times at the top, then we need our sorted set, set the value you want to sort to the score of sorted set, and set the specific data to the corresponding value. You only need to execute one ZADD command at a time.
3. Applications that need to accurately set expiration time
For example, you can set the score value of the sorted set mentioned above to the timestamp of the expiration time, then you can simply sort the expiration time and clear the expired data regularly, not only to remove the expired data in the Redis, you can completely regard the expiration time in the Redis as an index of the data in the database, use Redis to find out which data needs to expire and delete, and then accurately delete the corresponding records from the database.
4. Counter application
Redis commands are atomic, and you can easily use INCR,DECR commands to build a counter system.
5.Uniq operation to obtain all data weight values for a certain period of time
This set data structure using Redis is the most appropriate, just keep throwing the data into the set. Set means collection, so it will be automatically weighed.
6. Real-time system, anti-garbage system
Through the set function mentioned above, you can know whether an end user has performed an operation, and you can find the collection and combination of their operations for analysis and statistical comparison. Nothing is impossible, only unexpected.
Construction of Real-time message system by 7.Pub/Sub
Redis's Pub/Sub system can build real-time messaging systems, such as many examples of real-time chat systems built with Pub/Sub.
8. Build a queue system
You can build a queue system using list, and you can even build a queue system with priority using sorted set.
The above is all the content of this article "what is the Application scenario of Redis?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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.