Skip to content

Instantly share code, notes, and snippets.

@JakSprats
Created September 28, 2010 05:04
Show Gist options
  • Save JakSprats/600440 to your computer and use it in GitHub Desktop.
Save JakSprats/600440 to your computer and use it in GitHub Desktop.
/**
* Module dependencies.
*/
var redis = require('./index');
var client = redis.createClient(),
times = 800000,
curr = {},
start;
function next(){
var fn = queue.shift();
if (fn.length) {
var pending = 1;
fn("key", function(label){
var dur = new Date - start;
report(label, dur);
--pending || next();
});
} else {
fn();
}
}
var queue = [
// FLUSHALL
function(){
client.flushall(next);
},
function(buf, next){
var n = times;
start = new Date;
while (n--) client.set('key_' + n, 'val_' + n);
client.set("key", buf, function(err, res) {
next('SET');
});
},
function(buf, next){
var n = times;
start = new Date;
while (n--) client.get("key_" + n);
client.get("key", function (err, res) {
next('GET');
});
},
function(){
client.end();
}
];
client.on('connect', function(){
console.log('NUM: %d:', times);
next();
});
function report(label, c) {
console.log(' %s: ', label, (times/c)*1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment