This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var redisScan = require('redisscan'); | |
var redis = require('redis'); | |
var riak = require('riakpbc'); | |
var async = require('async'); | |
var args = require('optimist') | |
.usage('--import or --export Redis archives in Riak\nUsage: $0') | |
.boolean('import') | |
.boolean('export') | |
.boolean('debug') | |
.describe('import', "Import from Riak to Redis") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//whenever uncached images are added to the dom tree within target, | |
//replace them with a spinner gif until they're loaded | |
function replaceImages(target, spinner_src) { | |
var spinner, observer; | |
//detect support | |
if (window.MutationObserver) { | |
//preload spinner (probably a gif) | |
//if it's not ready for first use, oh well | |
spinner = new Image(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--EVAL "this script" 2 key lookup jsonvalue attribute | |
local key, lookup = unpack(KEYS); | |
local jsonvalue, attribute = unpack(ARGV); | |
local value = cjson.decode(jsonvalue); | |
local oldvalue = redis.call('GET', key); | |
--if this key was set before, remove the old lookup | |
if type(oldvalue) == 'string' then | |
oldvalue = cjson.decode(oldvalue); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
// ./generatelookup -l lookupkey -p somekey* -a attribute | |
var redis = require('redis').createClient(); | |
var async = require('async'); | |
var opt = require('optimist'); | |
opt.usage('$0 -l lookup -p pattern -a attribute'); | |
opt.demand(['l', 'p', 'a']); | |
var argv = opt.argv; | |
var iter = '0'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--2 key changelog update millisecond-epoch | |
local key, changelog = unpack(KEYS); | |
local update, epoch = unpack(ARGV); | |
local result = redis.call('SET', key, update); | |
local notice = cjson.encode({key = key, value = update, time = epoch}); | |
redis.call('ZADD', changelog, epoch, notice); | |
redis.call('ZREMRANGEBYSCORE', changelog, '-inf', epoch - 86400000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--EVAL "this script" 1 some-hash-key | |
local key = KEYS[1]; | |
local keyvalues = redis.call('HGETALL', key); | |
local result = {}; | |
--every other value is a key | |
for idx = 1, #keyvalues, 2 do | |
result[keyvalues[idx]] = keyvalues[idx + 1] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--EVAL "this script" 1 key userid password | |
local key = KEYS[1]; | |
local userid, pass = unpack(ARGV); | |
local hash = redis.sha1hex('SOME-STATIC-SALT'..string.sub(pass, 1, 2)..userid..string.sub(pass, 3)); | |
--no error, does hash match? | |
return {false, (redis.call('GET', key) == hash)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--EVAL 'this script' 1 some-key | |
local key = KEYS[1]; | |
local value = redis.call('GET', key); | |
local jvalue = cjson.encode(cmsgpack.unpack(value)); | |
return jvalue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* mapReduce | |
* arguments ( | |
* lup: levelup instance, | |
* map: function ({key, value}) { return [{key: mapkey, value: mapvalue}, ...]; }, | |
* reduce: function (mapkey, [mapvalue, ...]) { return reduced; }, | |
* callback: function (err, {mapkey: reduced, ...}) | |
* ) | |
* | |
* A map is called for each key pair. A map returns an array of key value pairs to be reduced. | |
* Key value pairs may be derived keys and values, or database keys and values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--EVAL "this script" 1 key_name new_item max_size | |
local key = KEYS[1]; | |
local item, max = unpack(ARGV); | |
redis.call('RPUSH', key, item); | |
redis.call('LTRIM', key, -max, -1); |