Redis principle
Redis uses its own implementation of the event separator, high efficiency, the internal use of non-blocking execution mode, throughput capacity is relatively large.
However, because the general memory operation is simple access operation, the thread takes a relatively short time, the main problem is on Io, so the Redis model is appropriate, but if a thread has a problem that causes the thread to take a long time, then Reids's single-threaded model is more efficient.
Quoted from the network:
The reasons for the overall speed are as follows:
1) Most requests are purely memory-operated (very fast)
2) Single threaded to avoid unnecessary context switching and competitive conditions
3) non-blocking IO
The internal implementation adopts epoll, and adopts the simple event framework which is implemented by epoll+ itself. Epoll read, write, close, connect to events, and then take advantage of the Epoll multiplexing feature, never waste a little time on Io
These 3 conditions are not independent of each other, especially the first one, if the request is time-consuming, with single-threaded throughput and performance can be imagined. It should be said that Redis has chosen the appropriate technical solution for a particular scenario.
About thread safety issues
Redis is actually a thread-gated concept that encloses a task in a thread, naturally avoiding thread-safety issues, but for composite operations that rely on multiple redis operations, locks are still required and may be distributed locks
Redis single-threaded model analysis