Created
April 13, 2015 23:41
-
-
Save adamloving/b9fae0e61d9d1411a9c3 to your computer and use it in GitHub Desktop.
Redis scan javascript promise (when) example
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
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