In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what other things redis can do besides caching. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Redis should be said to be one of the most popular NoSQL databases today. Redis is usually used as a caching component to cache data. However, in addition to caching data, there is a lot more Redis can do.
1. The latest list
For example, the latest news list on the news list page, if the total number is very large, try not to use select a from A limit 10, try redis's LPUSH command to build List, and stuff it one by one. But what if the memory is cleared? Also simple, if the query can not store key, use mysql query and initialize a List to redis.
2. Ranking application
The main redis data type used to implement this function is zset, an ordered collection of redis. Zset is an extension of the set type, which has one more order attribute than the original type. This attribute automatically adjusts the order values each time the data is inserted to ensure that the values are arranged continuously in a certain order.
Let's assume that it is a ranking of game experience values, then the main implementation idea is:
1. When a new player participates in the game, add a record in zset in redis (the record content depends on the specific requirements) score is 0
2. When the player's experience value changes, modify the player's score value.
3. Use the ZREVRANGE method of redis to get the ranking.
3. Counter application
Redis commands are atomic, and you can easily use INCR and DECR commands for atomic operations to build a counting system. Because of single threading, concurrency problems can be avoided, no errors can be guaranteed, and 100% millisecond performance.
For example, in a web application, if you want to know the number of clicks per day of the year, you can simply use the user's ID and related date information as keys and perform a self-increment operation each time the user clicks on the page.
4. Data weighting
Redis set can automatically arrange weights, when you need to store a list of data, but do not want to duplicate data, set is a good choice, and set provides an important interface to determine whether a member is in a set collection.
Implementation plan:
The internal implementation of set is a HashMap in which value is always null. In fact, the weight is arranged quickly by calculating hash, which is why set can determine whether a member is in the collection or not.
5. Real-time anti-garbage system
Anti-spam systems are usually based on keywords, using Redis to store relational words, which can take advantage of the high performance of Redis to provide stable and accurate real-time monitoring functions for the monitoring system, such as mail system, comment system and so on.
6. Real-time messaging system that can publish and subscribe
Pub/Sub systems in Redis can build real-time messaging systems, for example, many real-time chat applications built using Pub/Sub.
Design ideas:
The server sends messages (including title and content), the title is stored in redis according to certain rules, and the title (with the least amount of information) is pushed to the client. When the client clicks on the title, it gets the corresponding content to read.
If you don't read it, you can tell how many items are unread. Redis can count quickly.
Clean the cache according to a certain amount of time
Technical implementation:
Need redis database, client-side websocket, server-side websocket
7. Queue application
Queues are widely used in today's programs, such as log push, task processing, and so on. In the past, queues were usually implemented using http sqs, but in fact, queues can also be implemented using the list type of redis.
So much for sharing about what other things redis can do besides caching. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.
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.