Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Redis list or set pop method thread safe?

I'm building out a queuing service which will be multi-threaded. I need to make sure that Redis, our data backend, has a thread safe pop function for either lists or set types. The idea being that any number of threads can invoke Redis lpop or spop and not have any collisions. I'm not really sure how to test this and it doesn't explicitly state anywhere on the Redis page if the pop function is thread-safe.

like image 496
Marco Ceppi Avatar asked Jul 25 '12 20:07

Marco Ceppi


People also ask

Is Redis pop thread-safe?

Redis-py is thread safe because the connection pool only uses atomic methods when allocating/deallocating a connection.

Does Redis support multithreading?

Redis is single-threaded with epoll/kqueue and scale indefinitely in terms of I/O concurrency.

Is Python Redis client thread-safe?

Redis itself is thread-safe no matter which connection pool do you use.


1 Answers

from the benchmark page

Redis is a single-threaded server. It is not designed to benefit from multiple CPU cores. People are supposed to launch several Redis instances to scale out on several cores if needed. It is not really fair to compare one single Redis instance to a multi-threaded data store.

so as every command gets queued in a single thread you should be ok as there will never be two commands executing in parallel

like image 68
Sebastian Piu Avatar answered Oct 11 '22 18:10

Sebastian Piu