Posted at

Redisのeval/lua scriptをnode.jsで利用してみた

More than 3 years have passed since last update.


前提条件


  • Redis 3.2-rc3

  • Node.js 5.9.1

  • npm


    • node_redis 2.6.0-0




ソースコード

'use strict'

let redis = require("redis")
, client = redis.createClient()
;

let script = 'return redis.call("INCR", KEYS[1])';
client.eval(script, 1, 'foo', function (err, reply) {
console.log(reply.toString());
});

client.script('load', script, function (err, reply) {
let sha1 = reply.toString();
console.log(sha1);
client.evalsha(sha1, 1, 'foo', function (err2, reply2) {
console.log(reply2.toString());
client.quit();
});
});


実行結果

1

f793247de6e1e3c553cd42d39c812df499e679e4
2


参考資料