Created
March 14, 2016 22:56
-
-
Save amichaelgrant/44c8faa2e46055c10aaa to your computer and use it in GitHub Desktop.
Running Lua Script in Redis from Nodejs Client
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
-- setnex.lua | |
local key = ARGV[1] | |
local expiry = ARGV[2] | |
local value = ARGV[3] | |
local reply = redis.call("SETNX", key, value) | |
if 1 == reply then | |
redis.call("EXPIRE", key, expiry) | |
end | |
return reply | |
You can call it from node_redis like this: | |
client.eval(setnex_lua, 0, "mykey", 10, "myvalue", function (err, res) { | |
console.dir(err); | |
console.dir(res); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment