Bdfy
Bdfy

Reputation: 24709

Why lua script block redis-server?

I have a simple Lua script:

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

Why this script blocking the Redis server? If I run in another console command, for example: set test 1, result:

 BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.

Upvotes: 1

Views: 3853

Answers (2)

Dennis Anikin
Dennis Anikin

Reputation: 1011

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.

Upvotes: 3

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230521

Redis is single-threaded. Every command blocks it. EVAL is also a command, therefore it blocks redis.

Upvotes: 7

Related Questions