Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can multiple clients access same list concurrently without getting blocked in Redis?

Tags:

redis

Suppose there are two clients which are accessing same redis list datastructure. One is doing LPOP and other is doing RPUSH on the same list. Will there be a any contention between these two clients if they are running in parallel ? Will Redis lock mylist (below) when one client is accessing it,even if the clients running in parallel are accessing different ends of mylist?

Client 1
RPUSH mylist a
RPUSH mylist b

Client 2
LPOP mylist
LPOP mylist

Client 1 and Client 2 are running in parallel. Let me know if there will be contention in such a scenario.

like image 204
Ameliorator Avatar asked Feb 29 '12 06:02

Ameliorator


2 Answers

Redis is single-threaded, so every command that comes to it is (guaranteed to be) executed atomically. There is no parallel/concurrent access to redis' data structures, so in your scenario you cannot tell who's gonna execute first.

like image 166
hymloth Avatar answered Oct 13 '22 21:10

hymloth


one won't block the other, unless you use MULTI/EXEC to create a transaction, to avoid race conditions where one client POPS before the other client finishes to PUSH N values.

like image 32
Not_a_Golfer Avatar answered Oct 13 '22 22:10

Not_a_Golfer