can multiple clients access same list concurrently

2019-03-31 04:24发布

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.

标签: redis
2条回答
爷、活的狠高调
2楼-- · 2019-03-31 04:42

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.

查看更多
一夜七次
3楼-- · 2019-03-31 05:08

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.

查看更多
登录 后发表回答