Skip to content

Instantly share code, notes, and snippets.

@joshuawscott
Last active August 29, 2015 14:08
Show Gist options
  • Save joshuawscott/2a4c4d59950ec968e311 to your computer and use it in GitHub Desktop.
Save joshuawscott/2a4c4d59950ec968e311 to your computer and use it in GitHub Desktop.
Redis LUA stuff
-- Sets KEY to VALUE, preserving any existing TTL
-- Call with EVAL "..." 1 KEY VALUE
-- or
-- LOAD SCRIPT "..."
-- => <SHA1>
-- EVALSHA <SHA1> 1 KEY VALUE
local ttl = redis.pcall('ttl', KEYS[1])
if ttl == -1 then
return redis.pcall('set', KEYS[1], ARGV[1])
else
return redis.pcall('set', KEYS[1], ARGV[1], 'ex', ttl)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment