Created
January 12, 2017 14:53
-
-
Save akx/4cf0e09ee4f67a6a3c23e1458221e581 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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