github.com/benz9527/xboot@v0.0.0-20240504061247-c23f15593274/dlock/unlock.lua (about)

     1  -- MGET key1 key2 ...
     2  -- Fetch locked keys' values then unlock if all matched
     3  -- to target value.
     4  -- Redis Lua5.1 only support unpack() function,
     5  -- so we can't use table.unpack() here.
     6  local lockedValues = redis.call("MGET", unpack(KEYS))
     7  for i, _ in ipairs(KEYS) do
     8      if lockedValues[i] ~= ARGV[1] then
     9          return redis.error_reply("dlock token mismatch, unable to unlock")
    10      end
    11  end
    12  
    13  -- DEL key1 key2 ...
    14  -- Really delete keys (i.e. unlock).
    15  -- Redis Lua5.1 only support unpack() function,
    16  -- so we can't use table.unpack() here.
    17  redis.call("DEL", unpack(KEYS))
    18  return redis.status_reply("OK")