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 Penetration and Avalanche in redis

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you about what is penetration and avalanche in redis. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Redis Penetration and Avalanche?

1. Penetration:

Understanding: when redis acts on data cache, the cached data comes from db, and when key does not get value in redis, the logical code will get value from the database. This phenomenon is called cache traversal.

If there is a large amount of key passing through the cache and getting value from db, it will lead to a sharp increase in database pressure, or even paralysis.

Scheme: a. When there are a large number of invalid key, the value is obtained from the database and the loaddb is controlled using distributed mutexes.

b. Validate the request to determine whether it is a valid key, such as a Bloom filter.

c. Returns null directly, regardless of whether key takes a value or not. Set the expiration time for unstable caches, and if the cache expires, a thread starts asynchronously to get data from the db.

Comparison: to be added

two. Avalanche:

Understanding: redis server downtime

Solution: redis cluster, master-slave replication, Sentinel mode, redis-cluster

Compare:

Master-slave replication: read and write separation. Once the host is down, the slave needs to be upgraded manually, and it is prone to problems that cannot be written for a short time.

Sentinel mode: improve the read-write separation technology to automatically conduct master elections when the host is down, but the data is concentrated in master. When the master pressure is too high, it is difficult to expand capacity. High availability of redis can be achieved through Sentinel + master-slave replication, but

It is difficult to achieve high concurrency, that is, to disperse the pressure on the server. When there is little requirement for concurrency, it is recommended to use.

Redis-cluster: can achieve high availability, high concurrency, capacity expansion, reduction, maseter election. In the case of high concurrency, cluster is preferred to build redis cluster.

# # redis master-slave replication is used in conjunction with Sentinel mode: the former provides high availability, while the latter provides master election

# # redis-cluster= master-slave replication + sentinel mode + high concurrency + expandability.

1. Download redis

two。 Install gcc execute make command to install redis

Master-slave replication:

Start multiple redis,slaveofipport settings master,inforeplication to view redis master and slave information

Note: 1. When there is a password in master, slave must configure the file masterauth to set the password of the host, or use configsetmasterauth to set the password manually, otherwise, even if the slaveof holds

If the line is successful, the master-link-status is displayed as down, and after setting the masterauth password, up is displayed.

two。 When master-slave replication occurs and master goes down, you must manually switch slave to master, otherwise the slave machine will not be elected for master, and the slave master-link-status will be changed to down, and will always wait for master to start. Master-link-

Status reverts to up

3.master is writable and readable by default, and slave is read-only by default. You can modify slave-read-onlyyes: read-only no: read-write

Sentinel mode: master downtime automatic election master

Note: after master downtime restarts, it will be automatically synchronized to the post-election master as slave. It is important to keep the master and slave passwords the same, otherwise switching slave to maseter after the election will fail.

Cluster cluster: passwords also need to be consistent and need to be modified / usr/local/share/gems/gems/redis-3.3.3/lib/redis/client.rb

(https://img2018.cnblogs.com/blog/1909126/201912/1909126-20191229210642240-329425897.png) can be changed to the correct password

Cluster: each key uses CRC16 (key) 384 to decide which slot to place. A total of 16384 slots are assigned to different master (Cao is not assigned in slave), thus putting key into the corresponding master, when master

When downtime, its slave will be upgraded to master, and the data of the original master will be transferred to the new master.

Capacity expansion: add a new master-slave and allocate the slots of other master to the master of the new home, and the data in the slot will be transferred accordingly.

Downsizing: on the contrary.

Command: view cluster nodes

Clusternodes

Check the slot corresponding to key

Clusterkeyslotkey

View the correspondence between slot and node

Clusterslots

The above is the redis that the editor shares with you what is penetration and avalanche. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are 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: 285

*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

Database

Wechat

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

12
Report