Redis list 或 set pop 方法线程安全吗? [英] Is Redis list or set pop method thread safe?

查看:42
本文介绍了Redis list 或 set pop 方法线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个多线程的排队服务.我需要确保我们的数据后端 Redis 具有用于列表或集合类型的线程安全弹出函数.这个想法是任何数量的线程都可以调用 Redis lpopspop 并且不会有任何冲突.如果 pop 函数是线程安全的,我不确定如何测试它并且它没有在 Redis 页面上的任何地方明确说明.

解决方案

来自基准页面<块引用>

Redis 是一个单线程服务器.它不是为了从多个 CPU 内核.人们应该推出几个Redis如果需要,可以在多个核心上扩展实例.这不是真的将单个 Redis 实例与多线程数据进行比较是公平的存储.

所以当每个命令都在一个线程中排队时,你应该没问题,因为永远不会有两个命令并行执行

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.

解决方案

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

这篇关于Redis list 或 set pop 方法线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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