多个客户端可以同时访问同一个列表而不会在 Redis 中被阻止吗? [英] can multiple clients access same list concurrently without getting blocked in Redis?

查看:43
本文介绍了多个客户端可以同时访问同一个列表而不会在 Redis 中被阻止吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有两个客户端访问相同的 redis 列表数据结构.一个是做 LPOP,另一个是在同一个列表上做 RPUSH.如果这两个客户端并行运行,它们之间会不会有任何争用?Redis 是否会在一个客户端访问 mylist 时锁定它(如下),即使并行运行的客户端正在访问 mylist 的不同端?

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

客户端 1 和客户端 2 并行运行.让我知道在这种情况下是否会发生争用.

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

推荐答案

Redis 是单线程的,所以每一个到达它的命令都是(保证)以原子方式执行的.没有对 redis 数据结构的并行/并发访问,因此在您的场景中,您无法确定谁将首先执行.

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.

这篇关于多个客户端可以同时访问同一个列表而不会在 Redis 中被阻止吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆