gpt4 book ai didi

ruby - Redis流水线执行顺序

转载 作者:IT王子 更新时间:2023-10-29 05:57:41 24 4
gpt4 key购买 nike

我正在使用 rub redis gem。想知道我是否这样做:

redis.pipelined do
REDIS.del("users:#{current_user_id}:i-unread")
REDIS.lpush("users:#{current_user_id}:i-read", items)
REDIS.ltrim("users:#{current_user_id}:i-read", 0, Interaction::MAX_INTERACTIONS)
end

这个执行顺序有保证吗?

最佳答案

当然顺序是有保证的,不然流水线就没用了。您可以随时查看代码。例如,此测试明确假定命令按顺序执行:https://github.com/redis/redis-rb/blob/master/test/pipelining_commands_test.rb#L32

def test_bulk_and_multi_bulk_commands_mixed
r.pipelined do
r.lpush "foo", "s1"
r.lpush "foo", "s2"
r.mset("baz", "s3", "qux", "s4")
end

assert_equal 2, r.llen("foo")
assert_equal "s2", r.lpop("foo")
assert_equal "s1", r.lpop("foo")
assert_equal "s3", r.get("baz")
assert_equal "s4", r.get("qux")
end

关于ruby - Redis流水线执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17634826/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com