Skip to content

Instantly share code, notes, and snippets.

@adamloving
Created April 13, 2015 23:41
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 adamloving/b9fae0e61d9d1411a9c3 to your computer and use it in GitHub Desktop.
Save adamloving/b9fae0e61d9d1411a9c3 to your computer and use it in GitHub Desktop.
Redis scan javascript promise (when) example
var count = 0;
when.iterate(function(args) {
var cursor = parseInt(args[0]);
return redis.whenZScan('mykey', cursor || 0);
}, function predicate(args) {
var cursor = parseInt(args[0]);
return cursor === 0;
}, function handler(args) {
if (args.length > 1) {
var images = args[1];
count += images.length / 2; // because score follows key
}
}, [null])
.then(function() {
console.log('Done. count:', count);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment