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--
This article mainly introduces the reasons for using redis, which has certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.
Redis can do anything.
Caching, which is undoubtedly the best-known usage scenario for Redis today. It is very effective in improving server performance.
Ranking, if you use a traditional relational database to do this, it is very troublesome, and the use of Redis's SortSet data structure can be very convenient.
Calculator / speed limiter, using the atomic self-increasing operation in Redis, we can count the number of likes and visits of users. If this kind of operation is done with MySQL, frequent reading and writing will bring considerable pressure. The typical use scenario of speed limiter is to limit the frequency of a user's access to a certain API, which is commonly used when snapping up to prevent users from clicking crazily to bring unnecessary pressure.
Friend relationship, using some commands of the set, such as finding intersection, union, difference set and so on. It can easily handle some functions such as common friends, common hobbies and so on.
For simple message queuing, in addition to Redis's own publish / subscribe model, we can also use List to implement a queuing mechanism, such as arrival notification, mail delivery and other requirements, which do not need to be highly reliable, but will bring great DB pressure. List can be used to complete asynchronous decoupling.
Session sharing. Take PHP as an example. The default Session is saved in the server file. If it is a cluster service, the same user may fall on different machines, which will cause users to log in frequently. After using Redis to save Session, users can get the corresponding Session information no matter which machine they land on.
Redis can't do anything.
Redis feels that there are many things that can be done, but it is not omnipotent. Use it to get twice the result with half the effort in the right place. If abused, it may lead to instability of the system, higher cost and other problems.
For example, using Redis to save users' basic information, although it can support persistence, its persistence scheme can not guarantee the absolute landing of data, and may also lead to Redis performance degradation, because persistence too frequently will increase the pressure on Redis services.
To sum up, businesses with too much data and very low data access frequency are not suitable to use Redis. Too much data will increase the cost, and the access frequency is too low. It is a waste of resources to save in memory.
There is always a reason to choose.
There are some Redis scenarios mentioned above, so there are many other solutions for these scenarios, such as caching can be shared with Memcache,Session or implemented with MySql, and message queuing can be implemented with RabbitMQ. Why do we have to use Redis?
High speed, completely based on memory, implemented in C language, network layer uses epoll to solve high concurrency problems, single-threaded model avoids unnecessary context switching and competition conditions
Note:
A single thread simply means that a thread is used to process the client's request on the network request module, such as persistence, it will reopen a thread / process to process.
Among the rich data types, Redis has eight data types. Of course, the most commonly used data types are String, Hash, List, Set and SortSet. They all organize data based on key values. Each data type provides a wealth of operation commands, which can meet most of the needs. If there are special needs, you can also create new commands through lua scripts (atomicity).
In addition to the rich data types provided, Redis also provides personalized features such as slow query analysis, performance testing, Pipeline, transactions, Lua custom commands, Bitmaps, HyperLogLog, publish / subscribe, Geo, and so on.
Redis open source code in GitHub, the code is very simple and elegant, anyone can understand its source code; its compilation and installation is also very simple, without any system dependence; there is a very active community, a variety of client language support is also very perfect. In addition, it also supports transactions (unused), persistence, master-slave replication to make highly available, distributed possible.
As a developer, we can't make it a black box for what we use. We should go deep into it and get more familiar with it. Today I briefly talked about the usage scenarios of Redis and why I chose Redis over others. Next time, summarize the internal data structure of Redis and the time complexity of common commands.
Thank you for reading this article carefully. I hope it will be helpful for everyone to share the reasons for using redis. At the same time, I also hope that you will support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!
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.