redislua

Is BLPOP supported in Redis Lua functions?


When I try this crude example I get an immediate nil (not a 5 second block). Wasn't able to find anything in the documentation about supported or non supported commands in Lua functions

#!lua name=supported_commands

local function bl_pop_test(keys, args)
  local test_key = keys[1]

  return redis.call('BLPOP', test_key, 5)

end

redis.register_function('bl_pop_test', bl_pop_test)

My guess is that because functions block, calling a blocking command isn't supported? Just curious if anyone else has ever come across this..


Solution

  • From the BLPOP documentation:

    Using BLPOP inside a MULTI / EXEC block does not make a lot of sense as it would require blocking the entire server in order to execute the block atomically, which in turn does not allow other clients to perform a push operation. For this reason the behavior of BLPOP inside MULTI / EXEC when the list is empty is to return a nil multi-bulk reply, which is the same thing that happens when the timeout is reached.

    Lua scripts are executed atomically, that is, no other script or command will run while a script is running, which gives us the same transactional semantics as MULTI / EXEC (source).