Skip to content

Instantly share code, notes, and snippets.

@losinggeneration
Created March 24, 2014 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save losinggeneration/9741856 to your computer and use it in GitHub Desktop.
Save losinggeneration/9741856 to your computer and use it in GitHub Desktop.
Warlock Lua->Moon (just for fun)
--
-- Set a lock
--
-- KEYS[1] - key
-- KEYS[2] - ttl in ms
-- KEYS[3] - lock content
{key, ttl, content} = KEYS
lockSet = redis.call 'setnx', key, content
redis.call 'pexpire', key, ttl if lockSet == 1
lockSet
local key, ttl, content
do
local _obj_0 = KEYS
key, ttl, content = _obj_0[1], _obj_0[2], _obj_0[3]
end
local lockSet = redis.call('setnx', key, content)
if lockSet == 1 then
redis.call('pexpire', key, ttl)
end
return lockSet
--
-- Set a lock
--
-- KEYS[1] - key
-- KEYS[2] - ttl in ms
-- KEYS[3] - lock content
local key = KEYS[1]
local ttl = KEYS[2]
local content = KEYS[3]
local lockSet = redis.call('setnx', key, content)
if lockSet == 1 then
redis.call('pexpire', key, ttl)
end
return lockSet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment