7

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.

Ameliorator
  • 417
  • 1
  • 5
  • 10

2 Answers2

13

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.

hymloth
  • 6,869
  • 5
  • 36
  • 47
  • 3
    At the end of the day, all commands are served sequentially. Whoever comes first, gets served. Multiplexing refers to how all the incoming commands are picked from the listening socket and get serialized for execution. But seriously, your case is strongly affected by the randomness of concurrency. – hymloth Feb 29 '12 at 10:04
1

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.

Not_a_Golfer
  • 47,012
  • 14
  • 126
  • 92