Skip to content

Instantly share code, notes, and snippets.

@jgoodall
Last active December 27, 2015 02:19
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 jgoodall/7250936 to your computer and use it in GitHub Desktop.
Save jgoodall/7250936 to your computer and use it in GitHub Desktop.
[redis sorted sets](http://redis.io/commands#sorted_set) speed testing with [node-redis](https://github.com/mranney/node_redis). npm install -d node index.js
/* globals require, console, process, setInterval */
'use strict';
var async = require('async')
, redis = require('redis')
, client = redis.createClient();
client.on('error', function(err) {
console.error(err);
});
var key = "field";
var count = 0
, members = 100 // members of the set will range from 0 - members
, total = 1000000;
// inserts
var start = Date.now();
async.series([
// insert data
function(callback) {
async.whilst(
function () {
return count < total;
}
, function (inserted) {
count++;
var val = Math.floor(Math.random() * members);
client.zincrby(key, 1, val, function(err, res) {
inserted(err);
});
}
, function (err) {
// inserts completed
if (err) console.error(err);
var time = (Date.now() - start) / 1000;
console.info('Total time for ' + total + ' inserts: ' + time + ' seconds');
callback(err);
}
);
}
// read data
, function(callback) {
// show output
client.zrange(key, 0, -1, 'WITHSCORES', function(err, res) {
console.log(res);
callback(err);
});
}
]
// end
, function(err) {
if (err) console.error(err);
client.end();
}
);
{
"name": "redis-test",
"version": "0.0.1",
"main": "index.js",
"dependencies": {
"async": "~0.2",
"hiredis": "~0.1",
"redis": "~0.9"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment