0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

前提条件

  • 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

参考資料

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?