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

How to understand and master Redis

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

Share

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

This article introduces the relevant knowledge of "how to understand and master Redis". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Redis is an open source API that is written in ANSI C language, supports network, can be memory-based and persistent, Key-Value key-value pair database, and provides multiple languages.

The use environment of Redis

Read and write data with high concurrency

Reading and writing of massive data

Data that requires high scalability

The function of Redis

Data caching

Distributed lock

Support transaction

Support for message queuing

Support for data persistence

Why Redis is single threaded

Because the bottleneck of Redis is most likely to be machine memory or network bandwidth, not CPU. Since single thread is easy to implement and CPU is not the bottleneck, it is natural to use the bill of single thread. In addition, it is important to know that single thread does not represent slow. Node.js is also a high performance single thread.

Cache penetration

When querying a data that must not exist, because the cache misses, it needs to be queried from the database, and if the data cannot be found, it is not written to the cache, which will cause the non-existent data to be queried to the database every time, resulting in cache penetration.

Solution: if the data returned by a query is empty, the empty result is cached, but its expiration time is very short.

Redis persistence

RDB: snapshot storage of your data at specified time intervals

AOF: every write command received is appended to the file through the write function

Implementation of distributed Lock with Redis

Redis distributed lock, in fact, occupies a "location" in the system, and when other programs also want to occupy this "location", the execution continues successfully, and the failure can only give up or try again later.

Redis distributed lock cannot solve the problem of timeout. If the time exceeds the timeout of the lock, there will be a problem.

Elimination Strategy of Redis

Volatile-lru: select the least used data to be eliminated from datasets with an expiration time set

Volatite-ttl: select expired data to be eliminated from datasets with an expiration time set

Volatile-random: arbitrarily select data elimination from datasets with an expiration time set

Allkeys-lru: select the least recently used data elimination from the dataset

Allkeys-random: data elimination by randomly selecting data from the dataset

No-enviction: banning eviction data

This is the end of "how to understand and master Redis". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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