Skip to content

Instantly share code, notes, and snippets.

@evilpacket
Created January 19, 2015 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilpacket/2c772e3427365b788fdc to your computer and use it in GitHub Desktop.
Save evilpacket/2c772e3427365b788fdc to your computer and use it in GitHub Desktop.
redis stuff
127.0.0.1:6379> HGETALL checker:DEADC0DE:length
1) "3"
2) "3"
3) "6"
4) "3"
5) "9"
6) "1"
7) "5"
8) "2"
127.0.0.1:6379> HGETALL checker:DEADC0DE:colors
 1) "abc"
 2) "1"
 3) "red"
 4) "2"
 5) "orange"
 6) "2"
 7) "purple"
 8) "1"
 9) "notcolour"
10) "1"
11) "black"
12) "2"
{
"name": "redis_script_test",
"version": "0.0.0",
"description": "ERROR: No README.md file found!",
"main": "runscript.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": "",
"author": "Adam Baldwin",
"license": "MIT",
"dependencies": {
"hiredis": "^0.1.17",
"optimist": "~0.3.5",
"redis": "^0.12.1"
}
}
#!/bin/bash
node runscript.js ./test.lua 0 '["abc","red","red","orange","orange","purple","notcolour","black","black"]'
var fs = require('fs'),
redis = require('redis'),
argv = require('optimist').usage("$0 filename.lua [#keys] [arg1] ...")
.describe('d', 'show redis client debug')
.demand(1).argv;
client = redis.createClient('6379', '127.0.0.1');
if (argv.d) {
redis.debug_mode = true;
}
var script = fs.readFileSync(argv._[0]);
argv._[0] = script.toString();
if (argv._.length === 1) {
argv._.push(0);
}
client.send_command('EVAL', argv._, function (err, reply) {
console.log(arguments);
process.exit();
});
local checker_id = "DEADC0DE";
local input = ARGV[1];
local json = cjson.decode(input);
for i,color in ipairs(json) do
redis.call('HINCRBY', 'checker:' .. checker_id .. ':colors', color, 1);
redis.call('HINCRBY', 'checker:' .. checker_id .. ':length', string.len(color), 1);
end
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment