Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the usage scenario of Redis?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the relevant knowledge of "what is the use scenario of Redis". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "what is the use scenario of Redis" can help you solve the problem.

Summary of common Redis commands: including a summary of time complexity and data structures used within Redis for specific data types

Advanced functions of Redis: including persistence, replication, Sentinel, Cluster introduction

Understanding Redis: understanding memory, blocking; this part is very important, the previous introduction can become a technique, here should be part of the Tao

Development skills: mainly a summary of some development practices, including cache design and common potholes.

First open the first part of the content, to re-examine the Redis.

This series is based on: redis-3.2.12

Redis is not a panacea.

During the interview, I am often asked to compare the advantages and disadvantages of Redis and Memcache. I think it is not suitable to compare them together. One is that non-relational databases can do not only caching but also other things, and the other is just caching. We often compare the two, mainly because the most extensive application scenario of Redis is Cache. So what exactly can Redis do? What can I do?

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, the network layer uses epoll to solve high concurrency problems, and the single-thread model avoids unnecessary context switching and competition conditions. note: single-thread only means that the client request is processed with a request on the network request module, such as persistence, it will restart 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.

This is the end of the content about "what is the usage scenario of Redis". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report