Skip to content

Instantly share code, notes, and snippets.

@vekexasia
Created October 24, 2012 13:51
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 vekexasia/cb6563d10389cb9a5754 to your computer and use it in GitHub Desktop.
Save vekexasia/cb6563d10389cb9a5754 to your computer and use it in GitHub Desktop.
var redis = require('redis');
/* ENvironment variables */
/*
/**/
var dbhost = process.env.DBHOST;
var dbport = process.env.DBPORT;
var dbpass = process.env.DBPASSWORD;
/**/
/* / end environment variables */
var redisClient = redis.createClient(dbport, dbhost);
if (typeof(dbpass) !== 'undefined') {
redisClient.auth(dbpass, function (err, data) {
redisClient.select('0',function(err, data) {
doTest();
});
});
} else {
doTest();
}
function doTest() {
var bit = [];
for (i=0;i<300;i++) {
bit.push(i);
}
var multi = redisClient.multi();
multi.incr('test');
multi.sadd('user:fb:test:friends', bit);
multi.exec(function(err, replies) {
// Should check this works.
// console.log(err); // null
// console.log(replies); // [1, 300] or [n, 0] --- depending on the number of times you launch this
redisClient.smembers('user:fb:test:friends', function(err, data) {
if (data[data.length-1] === null) {
console.error("KO");
} else {
console.log("OK");
}
//console.log("Length: "+data.length); // output 300
redisClient.end();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment