Lua script loading tool for Redis.
npm install lured

Lua script loader for Redis.
scripts is an object in with the following structure:``js`
var scripts = {
foo: {
script: "return 1", // your lua script for 'foo'
sha: "e0e1f9fabfc9d4800c877a703b823ac0578ff8db" // filled by lured
},
bar: {
script: "return 2", // your lua script for 'bar'
sha: "7f923f79fe76194c868d7e1d0820de36700eb649" // filled by lured
}
};sha
Where, properties are automatically filled by lured.
`js
var fs = require('fs')
var scripts = {
foo: {
script: fs.readFileSync(__dirname + '/foo.lua', {encoding:'utf8'})
},
bar: {
script: fs.readFileSync(__dirname + '/bar.lua', {encoding:'utf8'})
}
};
var client = require('redis').createClient();
var lured = require('lured').create(client, scripts);
// Load all scripts on to redis server.
lured.load(function (err) {
if (err) { / handler error /}
else {
// Do your cool stuff here
// Now you can safely do something like this:
client.multi()
.evalsha(scripts.foo.sha, 0)
.evalsha(scripts.bar.sha, 0)
.exec(function(err, replies) {
// Check your replies.
});
}
});
`Notes
$3
When redis client emits 'connect' event, lured will check if the scripts are still cached, if not it will reload the scripts for you. If you need to track down the underlying behavior, set a listener on 'state' event.