The reasons for the speed in general are as follows:
1) The vast majority of requests are pure memory operations (very fast)
2) Using a single thread to avoid unnecessary context switches and race conditions
3) Non-blocking IO
The internal implementation adopts epoll, and adopts the simple event framework implemented by epoll+ itself. Read, write, close, and connect in epoll are converted into events, and then use the multiplexing feature of epoll to never waste a little time on io
These three conditions are not independent of each other, especially the first one. If the requests are time-consuming, it is conceivable to use single-threaded throughput and performance. It should be said that redis has chosen a suitable technical solution for a special scenario.
About thread safety
Redis actually adopts the concept of thread closure, enclosing tasks in a thread, which naturally avoids thread safety problems, but for compound operations that need to rely on multiple redis operations, locks are still required, and there may be distributed locks .