In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
What are the knowledge points of this article "what are the common uses of Redis?" most people do not understand, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what are the common uses of Redis?"
I. Common ways of use
Several common uses of Redis include:
1.Redis single copy
2.Redis multiple copies (master-slave)
3.Redis Sentinel (sentinel)
4.Redis Cluster
5.Redis developed by itself.
Advantages and disadvantages of various modes of use 1. Redis single copy
Redis single copy, which uses a single Redis node deployment architecture, has no backup node to synchronize data in real time, and does not provide data persistence and backup strategy. It is suitable for pure cache business scenarios with low data reliability requirements.
Advantages:
Simple architecture and easy deployment
Cost-effective: no backup node is needed when using the cache (single instance availability can be guaranteed by supervisor or crontab). Of course, in order to meet the high availability of the business, a spare node can be sacrificed, but only one instance provides services at the same time.
High performance.
Disadvantages:
Do not guarantee the reliability of the data
After the cache is used and the process is restarted, the data is lost, even if there is a spare node to solve the high availability, but it still can not solve the cache warm-up problem, so it is not suitable for businesses with high data reliability requirements.
High performance is limited by the processing power of single-core CPU (Redis is a single-threaded mechanism), and CPU is the main bottleneck, so it is suitable for scenarios with simple operation commands and less sorting and computing. You can also consider using Memcached instead.
2. Redis multiple copies (master-slave)
Redis multi-replica adopts master-slave (replication) deployment structure. Compared with single copy, the most important feature is real-time data synchronization between master and slave instances, and provides data persistence and backup strategy. Master-slave instances are deployed on different physical servers. According to the basic environment configuration of the company, you can provide services and read-write separation strategy at the same time.
Advantages:
High reliability: on the one hand, the dual-computer active / standby architecture is adopted, which can automatically switch between the master and standby when the master database fails, and upgrade the slave database to provide services for the master database to ensure the smooth operation of the service; on the other hand, turning on the data persistence function and configuring a reasonable backup strategy can effectively solve the problems of data misoperation and abnormal data loss.
Read-write separation strategy: the slave node can expand the read capacity of the master database node and effectively deal with large concurrency read operations.
Disadvantages:
Fault recovery is complex. If there is no RedisHA system (need to be developed), when the master database node fails, it is necessary to manually promote a slave node to the master node, notify the business side to change the configuration, and let other slave database nodes copy the new master database node. The whole process requires human intervention, which is tedious.
The writing ability of the main library is limited by a single machine, so sharding can be considered.
The storage capacity of the main library is limited by a single machine, so Pika can be considered.
The disadvantages of native replication are also prominent in earlier versions, for example, after Redis replication is interrupted, Slave will initiate psync, and if the synchronization is not successful, full synchronization will be carried out, and the full backup of the main library may cause stutters in milliseconds or seconds at the same time; and because of the COW mechanism, the memory of the main library will overflow and the program exits abnormally or downtime in extreme cases. The backup files generated by the master library node result in the consumption of server disk IO and CPU (compression) resources; the number of GB backup files sent leads to a sharp increase in server egress bandwidth and blocking requests. It is recommended to upgrade to the latest version.
3. Redis Sentinel (Sentinel)
Redis Sentinel is a native high availability solution launched by the community version, and its deployment architecture mainly consists of two parts: Redis Sentinel cluster and Redis data cluster.
Redis Sentinel cluster is a distributed cluster composed of several Sentinel nodes, which can realize fault discovery, automatic fault transfer, configuration center and client notification. The number of nodes in Redis Sentinel should satisfy the odd number of 2n+1 (n > = 1).
Advantages:
Redis Sentinel cluster deployment is simple
It can solve the problem of high availability switching in Redis master-slave mode.
It is very convenient to realize the linear expansion of Redis data nodes, which can easily break through the single-thread bottleneck of Redis itself, and can greatly meet the business needs of Redis with large capacity or high performance.
It is possible to implement a set of Sentinel to monitor a set of Redis data nodes or multiple groups of data nodes.
Disadvantages:
The deployment is more complicated than the Redis master-slave mode, and the principle understanding is more complicated.
Waste of resources. Slave nodes in Redis data nodes do not provide services as backup nodes.
Redis Sentinel is mainly aimed at the high availability handover of the master node in the Redis data node. The failure decision of the Redis data node can be divided into subjective offline and objective offline. For the slave node of Redis, the subjective offline operation is done to the node, and the failover is not performed.
It can not solve the problem of separation of reading and writing, and it is relatively complex to implement.
Recommendations:
If you monitor the same business, you can choose a set of Sentinel cluster monitoring scheme for multiple groups of Redis data nodes, and vice versa, choose a set of Sentinel scheme for monitoring a group of Redis data nodes.
The recommended setting in the sentinel monitor configuration is half plus 1 of the Sentinel node. When the Sentinel is deployed in multiple IDC, the number of Sentinel deployed in a single IDC is not recommended to exceed (number of Sentinel-quorum).
Set parameters reasonably, prevent miscut, control switching sensitivity control:
A. Quorum
B. Down-after-milliseconds 30000
C. Failover-timeout 180000
D. Maxclient
E. Timeout
The server time of each node deployed should be synchronized as much as possible, otherwise the timing of the logs will be confused.
Redis recommends using pipeline and multi-keys operations to reduce the number of RTT and improve the efficiency of requests.
Set the configuration center (zookeeper) on your own to facilitate the client's link access to the instance.
4 、 Redis Cluster
Redis Cluster is a Redis distributed cluster solution launched by the community version, which mainly solves the distributed requirements of Redis. For example, when you encounter bottlenecks such as stand-alone memory, concurrency and traffic, Redis Cluster can achieve a good load balancing purpose.
The minimum configuration of the Redis Cluster cluster node is more than 6 nodes (3 master and 3 slaves), in which the master node provides read and write operations, and the slave node serves as a backup node, which does not provide requests and is only used for failover.
Redis Cluster uses virtual slot partitioning, and all keys are mapped to zero 16383 integer slots according to the hash function. Each node is responsible for maintaining part of the slot and the mapped key value data printed by the slot.
Advantages:
Non-central architecture
The data is distributed in multiple nodes according to slot storage. The data is shared among nodes, and the data distribution can be adjusted dynamically.
Scalability: can be linearly extended to more than 1000 nodes, nodes can be dynamically added or deleted
High availability: when some nodes are unavailable, the cluster is still available. By adding Slave as standby data copy, fault automatic failover can be realized, state information is exchanged between nodes through gossip protocol, and the role promotion from Slave to Master is completed by voting mechanism.
Reduce the cost of operation and maintenance and improve the expansibility and availability of the system.
Disadvantages:
The implementation of Client is complex, and the driver is required to implement Smart Client, cache slots mapping information and update it in time, which improves the difficulty of development, and the immaturity of the client affects the stability of the business. At present, only JedisCluster is relatively mature, and the exception handling part is not perfect, such as the common "max redirect exception".
The node will block for some reason (the blocking time is greater than clutser-node-timeout) and be judged to be offline. This kind of failover is not necessary.
Data is replicated asynchronously, which does not guarantee the strong consistency of the data.
When multiple businesses use the same cluster, it is impossible to distinguish hot and cold data according to statistics, so the isolation of resources is poor, and it is easy to influence each other.
Slave acts as a "cold backup" in the cluster, which can not relieve the reading pressure. Of course, the utilization of Slave resources can be improved through the reasonable design of SDK.
Key batch operation restrictions. For example, using mset and mget, only Key with the same slot value is supported to perform batch operation. For Key mapped to different slot values, because Keys does not support cross-slot queries, it is not friendly to perform mset, mget, sunion, and other operations.
The support of Key transaction operation is limited, only the transaction operation of multiple key on the same node is supported, and the transaction function cannot be used when multiple Key are distributed on different nodes.
As the minimum granularity of data partition, Key can not map a large key object such as hash, list and so on to different nodes.
Multiple database spaces are not supported. Redis on a single machine can support up to 16 databases. In cluster mode, only one database space can be used, that is, db 0.
The replication structure supports only one layer, the slave node can only copy the master node, and the nested tree replication structure is not supported.
Avoid the generation of hot-key, causing the main library node to become the deficiency of the system.
Avoid the generation of big-key, resulting in network card burst, slow query and so on.
Retry time should be greater than cluster-node-time time.
Redis Cluster does not recommend using pipeline and multi-keys operations to reduce the scenarios generated by max redirect.
Share an interview book "Java Core knowledge points arrangement. Pdf", covering JVM, locks, high concurrency, reflection, Spring principles, microservices, Zookeeper, databases, data structures, etc., and Java208 test questions (including answers) can be obtained free of charge by joining (Java Advanced Architecture) 705127209!
5. Redis self-research
The high availability solution developed by Redis is mainly reflected in the configuration center, fault detection and failover processing mechanism, which usually needs to be customized according to the actual online environment of the enterprise business.
Advantages:
High reliability and high availability
High self-controllability
Meet the actual needs of the business, good scalability, good compatibility.
Disadvantages:
The implementation is complex and the development cost is high.
It is necessary to set up supporting peripheral facilities, such as monitoring, domain name service, database for storing metadata information, etc.
The maintenance cost is high.
The above is about the content of this article on "what are the common uses of Redis". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please 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: 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.