Last active
December 27, 2015 02:19
-
-
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
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
/* 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(); | |
} | |
); |
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
{ | |
"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