moon-bucket
Advanced tools
Comparing version 0.0.1 to 0.0.2
var fs = require('fs'); | ||
var scripts = require('./sha'); | ||
var client; | ||
@@ -29,3 +30,4 @@ | ||
fs.readFile('./scripts/join.lua', 'utf8', function(err, script) { | ||
client.eval([script, numKeys, keys, hashNamespace, limit], function(err, res) { | ||
console.log(scripts['join']); | ||
client.evalsha([scripts['join'], numKeys, keys, hashNamespace, limit], function(err, res) { | ||
var reply; | ||
@@ -32,0 +34,0 @@ |
{ | ||
"name": "moon-bucket", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A bucket of Lua scripts for Redis", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -91,2 +91,17 @@ # :honey_pot: moon-bucket :last_quarter_moon_with_face: | ||
## Technical stuff | ||
Internally when using node.js to call any of the methods available (like `join`), we're actually calling node redis' `evalsha` method on the corresponding sha1 hash in `/sha/index.js`. This is more performant, because we don't have to actually read any files from the file system (in other words, we never make a call to read anything from the `scripts` directory directly; instead, we just make redis evaluate the sha1 hash of the script). So, `moonBucket.join(/* args */)` actually calls something like `redis-cli evalsha b0eff2712326fb5b1cda561a013a0fcc16cb8d85 [...args]`: | ||
``` | ||
// ./sha/index.js | ||
module.exports = { | ||
// this is the hash of the corresponding lua script | ||
"join":"b0eff2712326fb5b1cda561a013a0fcc16cb8d85" | ||
}; | ||
``` | ||
If you want to add your own script to `scripts`, you'll need to implement the method in `./index.js` and then run `./.bin/compile-sha` in order to re-create the sha map. | ||
## What's in a name? | ||
@@ -93,0 +108,0 @@ |
7850
10
75
113