为什么 Lua 脚本会阻塞 Redis 服务器?

我有一个简单的 Lua 脚本:

while ( i < 500000 ) do
    redis.call("zadd", 'test1', i, i)
    redis.call( "expire", 'test1', 600 )
    i = i + 1
end

local res = redis.call("zrange", "test1", 0, 500000 )

for k,a in pairs(res) do
    redis.call("zadd", 'test2',k,a)
end

为什么这个脚本会阻塞 Redis 服务器? 如果我在另一个控制台运行命令,例如:set test 1,结果是:

BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
点赞
用户125816
用户125816

Redis 是单线程的,每个命令都会阻塞它。EVAL 也是一个命令,因此它会阻塞 redis。

2012-06-29 12:19:18
用户5094838
用户5094838

那是我们在Mail.Ru和myMail中使用Tarantool NoSQL数据库而不是我们之前尝试使用的Redis的原因。在Tarantool中,每个命令都在单独的纤维中执行,不会阻塞其他纤维。同样,Lua脚本也不会相互阻塞。

(翻译后保留原本的markdown格式如下:)

That is why we at Mail.Ru and at myMail use Tarantool NoSQL database instead of Redis that we also were trying to use. In Tarantool every command is being executed in a separate fiber and doesn't block another one. The same thing to Lua scripts - they don't block each other.

2015-07-11 07:04:46