In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the difference between redis and memcached? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
What's the difference between redis and memcached? Redis supports complex data structures
Compared with memcached, redis has more data structures and can support richer data operations. If you need caching to support more complex structures and operations, redis would be a good choice.
Redis natively supports cluster mode
In the redis3.x version, cluster mode is supported, while memcached does not have the native cluster mode, so you need to rely on the client to write data to the cluster.
Performance comparison
Because redis uses only a single core, while memcached can use multiple cores, on average, redis performs better than memcached in storing small data on each core. In the data of more than 100k, the performance of memcached is higher than that of redis. Although redis has recently optimized the performance of storing big data, it is still slightly inferior to memcached.
The threading model of redis
Redis internally uses the file event handler file event handler, which is single-threaded, so redis is called a single-threaded model. It uses IO multiplexing mechanism to monitor multiple socket at the same time, and selects the corresponding event handler to process according to the events on the socket.
The structure of the file event handler consists of four parts:
Multiple socket
IO multiplexing program
File event dispatcher
Event handler (connection reply processor, command request processor, command reply processor)
Multiple socket may produce different operations concurrently, and each operation corresponds to a different file event, but the IO multiplexer listens to multiple socket and queues the events generated by socket. The event dispatcher takes one event from the queue at a time and hands it to the corresponding event processor for processing.
Let's look at a communication process between the client and redis:
When the client socket01 requests the server socket of redis to establish a connection, server socket will generate an AE_READABLE event. After listening to the event generated by server socket, the IO multiplexer will press the event into the queue. The file event dispatcher gets the event from the queue and gives it to the connection reply processor. The connection reply processor creates a socket01 that can communicate with the client and associates the AE_READABLE event of that socket01 with the command request processor.
Suppose that the client sends a set key value request, and the socket01 in the redis generates an AE_READABLE event, and the IO multiplexer presses the event into the queue, and the event dispatcher gets the event from the queue. Since the previous AE_READABLE event of socket01 has been associated with the command request processor, the event dispatcher hands the event to the command request processor for processing. The command requests the processor to read the key value of socket01 and complete the setting of key value in its own memory. When the operation is complete, it associates the AE_WRITABLE event of socket01 with the command reply processor.
If the client is ready to receive the return result at this time, the socket01 in redis will generate an AE_WRITABLE event, which is also pressed into the queue, and the event dispatcher finds the associated command reply processor, and the command reply processor inputs a result of this operation to the socket01, such as ok, and then disassociates the AE_WRITABLE event of socket01 with the command reply processor.
This completes a communication.
Why is the redis single-threaded model so efficient?
Pure memory operation
The core is IO multiplexing mechanism based on non-blocking
On the contrary, single thread avoids the problem of frequent context switching of multiple threads.
After reading the above, have you mastered the difference between redis and memcached? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.