- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
有没有办法自动从列表中弹出一个项目并将其添加到集合中?
我的案例场景是我有一个独特项目的“工作队列”列表,我想跟踪“进行中”集中正在处理的内容。如果我的工作进程在处理某个项目时崩溃,这也将允许“进行中”集中的项目重新排队。
我希望它是原子的,这样从列表中弹出的任何内容都将始终在集合中。我只是不知道如何使用 MULTI/EXEC 执行此操作,即:
redis> MULTI
OK
redis> LPOP workqueue
"foobar"
redis> SADD inprog "foobar"
redis> EXEC
最佳答案
为什么你希望你的“进行中”收藏是一个集合?您可以简单地为正在进行的项目使用一个列表。
命令RPOPLPUSH “Right Pop,Left Push”正是为这个用例而设计的。
Atomically returns and removes the last element (tail) of the list stored at source, and pushes the element at the first element (head) of the list stored at destination
如果您确实想为正在进行的项目使用 Set,则必须使用 lua 脚本并使用 eval 调用它。 .
关于list - redis:原子 LPOP 和 SADD 可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12135027/
上次我查看 logstash 文档说官方的 redis 输入插件使用“blpop”命令从 redis 获取消息。 (如果我错了,请纠正我。) 但是,我们的 redis 集群不允许命令“blpop”。所
我需要从 Redis 队列执行一个简单的 lpop。在 go lang 中,如果我使用 blpop 使用阻塞弹出,则 foll 代码有效 reply, err := redis.Strings(con
使用 LPOP 时如果客户端在 redis 服务器执行命令时断开连接,弹出的项目会发生什么情况? 更具体地说,元素是否在未交付的情况下被丢弃,或者由于命令未成功而保留在内存中? 感谢任何帮助/指点。
我看到了这种奇怪的行为。我对一个键执行 lpush 操作。有一个不同的服务可以监听键通知并尝试lpop 值。但奇怪的是它返回空值。如果我用 0 作为索引执行 lindex,我会得到值。所以,我肯定知道
我有一个redis列表 a, b, c ,d ,e ,f g, h 在我对函数的回调中,我获得了元素的索引,我想删除该索引。 LPOP 和 RPOP 对我不起作用。如何在 Redis 中根据索引而不是
我正在尝试在 Redis 中构建 FIFO 队列,但我只是担心并发性。如果 2 个客户端尝试同时进行 RPOP 操作怎么办? 如果 RPOP/LPOP 不是原子的,那么如何使用 MULTI/EXEC
Tornado 和 Redis 的新手我发现这里有人有同样的问题,tornado-redis: RPOP works but BRPOP doesn't?但我仍然不明白为什么,以及如何解决我的问题 代
我尝试了几种消息/作业队列系统,但它们似乎都增加了不必要的复杂性,而且我总是以队列进程无缘无故死机和神秘的日志消息告终。 所以现在我想用 Redis 制作自己的队列系统。你会怎么做? 据我所知,Red
有没有办法自动从列表中弹出一个项目并将其添加到集合中? 我的案例场景是我有一个独特项目的“工作队列”列表,我想跟踪“进行中”集中正在处理的内容。如果我的工作进程在处理某个项目时崩溃,这也将允许“进行中
我有一个应用程序在调用 lpop 时不断循环。使用 top 命令,我可以看到 Redis 使用了 64% 的 CPU,而我的应用程序使用了 101%。 我正在使用 Redis 创建队列和工作器。我的工
我正在使用 Redis 作为内存数据库进行实时分析。在我的分析中,我继续在不断增长的 Redis-list 上执行 rpop 以对每个 rpop'ed 项目执行分析。为了清理 Redis-list 并
我是一名优秀的程序员,十分优秀!