Last active
August 29, 2015 14:08
-
-
Save joshuawscott/2a4c4d59950ec968e311 to your computer and use it in GitHub Desktop.
Redis LUA stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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