Skip to content

Instantly share code, notes, and snippets.

@akx
Created January 12, 2017 14:53
Show Gist options
  • Select an option

  • Save akx/4cf0e09ee4f67a6a3c23e1458221e581 to your computer and use it in GitHub Desktop.

Select an option

Save akx/4cf0e09ee4f67a6a3c23e1458221e581 to your computer and use it in GitHub Desktop.
const shortid = require('shortid');
const redis = require("redis");
const client = redis.createClient();
function t() {
const id = shortid.generate();
client.sadd('sids', id, (err, res) => {
if(err) throw err;
if(res != 1) { // redis will return the number of new items, so if we added anything other than 1, something broke
throw new Error('gack, duplicate ' + id);
}
t();
});
}
for(var i = 0; i < 50; i++) { // start multiple "workers" to add items
t();
}
setInterval(() => {
client.scard('sids', (err, res) => {
console.log(res);
});
}, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment