Redis is single-threaded:
Single-threaded refers to the network request module using one thread (so there is no need to consider concurrency safety), that is, one thread handles all network requests. Other modules still use multiple threads.
##Thread safety (Recommended learning: Redis video tutorial)
Redis actually adopts the concept of thread closure, which encloses tasks in one thread, which naturally avoids thread safety issues. However, for composite operations that rely on multiple redis operations, locks are still required, and they may be distributed. style lock.
The reasons why redis can execute quickly:
(1) Most requests are pure memory operations (very fast)(2 ) Uses a single thread to avoid unnecessary context switching and race conditions
(3) Non-blocking IO - IO multiplexing (What does IO multiplexing mean?)
What are the benefits of using Redis?
It is fast because the data is stored in memory, similar to HashMap. The advantage of HashMap is that the time complexity of search and operation is O(1)Redis database usage introductory tutorial column to learn!
The above is the detailed content of Is redis thread-safe?. For more information, please follow other related articles on the PHP Chinese website!