In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Recently, I have done some research on Huawei cloud distributed cache product redis, so I have sorted out some basic knowledge to share with you. The first thing to share with you is how to use Redis in detail from different angles.
The editor will make a detailed analysis from the following nine angles, hoping to help you all.
1. Network model:
Redis uses a single-threaded IO reuse model and encapsulates a simple AeEvent event handling framework, which mainly implements epoll, kqueue and select. For simple IO operations, single thread can maximize the speed advantage, but Redis also provides some simple computing functions, such as sorting, aggregation, etc., for these operations, the single-thread model will seriously affect the overall throughput. In the process of CPU computing, The entire IO dispatch is blocked.
2. Memory management
Redis uses on-site memory to store data, and rarely uses free-list to optimize memory allocation. There will be memory fragments to a certain extent. Redis and storage command parameters will store data with expiration time separately and call them temporary data. Non-temporary data will never be removed, even if there is not enough physical memory. As a result, swap also does not eliminate any non-temporary data (but attempts to eliminate some temporary data), which makes Redis more suitable for storage than cache.
3. Data consistency:
On the issue of consistency, I feel that redis is not as good as memcached. Memcached provides cas commands to ensure the consistency of multiple concurrent access operations to the same data. Redis does not provide cas commands, which is not guaranteed, but Redis provides transactional functionality to ensure the atomicity of a string of commands without being interrupted by any operation.
4. Supported KEY types:
In addition to key/value, Redis also supports list,set,sorted set,hash and many other data structures, providing KEYS for enumerating operations, but cannot be used online. If you need to enumerate online data, Redis provides a tool that can directly scan its dump file and enumerate all the data. Redis also provides persistence and replication functions.
Fifth, the client supports:
Redis officially provides rich client support, including most programming language clients. For example, I chose the officially recommended Java client Jedis for this test. It provides rich interfaces and methods so that developers do not need to relate to internal data slicing, reading data routing, etc., just a simple call, very convenient.
VI. Data replication:
Starting from 2.8, Slave periodically (once per second) initiates an Ack to confirm the progress of the replication stream (replication stream). The detailed process of Redis replication is as follows:
If a Slave is set, it issues a SYNC command whether it connects for the first time or reconnects to the Master
When Master receives the SYNC command, it does two things:
A) Master executes BGSAVE: writes data to disk in the background (rdb snapshot)
B) Master also buffers newly received commands for writing and modifying datasets (non-query class)
When Master saves the data to the snapshot file in the background, Master transfers the snapshot file to Slave, and Slave clears the memory and loads the file into memory
And Master will also forward the commands previously collected into the buffer to Slave,Slave to execute these commands in the form of Reids command protocol to achieve synchronization with Master.
Since then, Master/Slave will continue to synchronize commands asynchronously to achieve the same synchronization of the final data.
It should be noted that any reconnection between Master and Slave will trigger a full synchronization operation. But after 2.8, it may also be a partial synchronization operation.
At first, when the connection between Master and Slave is broken, continuous replication can be used instead of full synchronization between them.
The Master side maintains a memory buffer (in-memory backlog) for the replication stream to record the most recently sent replication stream commands; at the same time, both Master and Slave maintain a replication offset (replication offset) and the current Master server ID (Masterrun id).
When the network is disconnected and Slave tries to reconnect:
a. If the MasterID is the same (that is, it is still the Master server before the disconnection), and the historical commands from the time of disconnection to the current moment still exist in the memory buffer of Master, then Master will send all commands for the missing period to Slave for execution, and the replication work can continue.
b. Otherwise, a full copy operation is still required.
7. Separation of reading and writing:
Redis supports read-write separation and is easy to use. You only need to configure the Redis read server and write server in the configuration file. Multiple servers are separated by commas as follows:
8. Horizontal dynamic expansion:
After three years, I finally came to look forward to the Redis 3.0th. The new version mainly implements the function of Cluster, and data migration will be carried out automatically after adding and deleting cluster nodes. The core of online reconfiguration of Redis clusters is the ability to move slots from one node to another. Because a hash slot is actually a collection of keys, what a Redis cluster really needs to do when it rehash is to move some keys from one node to another.
IX. Data elimination strategy:
When the Redis in-memory dataset size rises to a certain size, the data elimination strategy is implemented. Redis provides 6 data elimination strategies:
Volatile-lru: select the least recently used data elimination from the dataset with an expiration time set (server. DB [I]. Obsolete).
Volatile-ttl: select the expired data from the dataset (server. DB [I]. Expires) that will expire.
Volatile-random: arbitrarily select data elimination from a dataset with an expiration time set (server. DB [I]. Expires).
Allkeys-lru: select the least recently used data elimination from the dataset (server. DB [I]. Dict).
Allkeys-random: data elimination from any selection of the dataset (server. DB [I]. Dict)
The little ones are all newer things. I hope you don't laugh at me. As a rookie, I also hope to help others. After all, you really need to learn and sum up to enter this industry. If you want to have an in-depth discussion, you are welcome to come to China to post for the Cloud Community Forum. Here, big names are gathered, and you can also serve as a cloud help center. The materials inside are also carefully compiled practical information. Thank 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.
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.