Last active
June 22, 2018 09:41
-
-
Save Petelin/30dc183220160039c602bac167f16a92 to your computer and use it in GitHub Desktop.
this lua script is used to in redis. it will set to the key if the value is bigger than the `updateat:{timestamp}`, if no udpateat founded update as normal
This file contains hidden or 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
local a = redis.call('get',KEYS[1]); | |
if a and a:find("^updateat:") ~= nil then | |
-- this key already update by anther thread. so we test | |
if tonumber(string.sub(a, 10, string.len(a))) <= tonumber(KEYS[2]) then | |
return redis.call('set',KEYS[1], KEYS[3]); | |
end | |
return; | |
end | |
return redis.call('set',KEYS[1], KEYS[3]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
127.0.0.1:6379> set foo updateat:100
redis-cli --eval /tmp/a.lua foo 120 message --> success
redis-cli --eval /tmp/a.lua foo 80 message --> failed
redis-cli --eval /tmp/a.lua foo2 80 message --> success, since no foo2