2.0.0 • Published 9 years ago
redisscan v2.0.0
RedisScan
Recursively scans the keyspace of a Redis 2.8+ instance using SCAN, HSCAN, ZSCAN, & SSCAN as well as Lists.
Fairly safe in a production environment as it does NOT use KEYS * to iterate.
Optionally pass a redis pattern to filter from.
Install
npm install redisscan
Example
var redisScan = require('redisscan');
var redis = require('redis').createClient();
redisScan({
redis: redis,
pattern: 'awesome:key:prefix:*',
keys_only: false,
each_callback: function (type, key, subkey, length, value, cb) {
console.log(type, key, subkey, length, value);
cb();
},
done_callback: function (err) {
console.log("-=-=-=-=-=--=-=-=-");
redis.quit();
}
});redisScan(parameters):
redis: requirednode-redisclient instancepattern: optional wildcard key pattern to match, e.g:some:key:pattern:*docskeys_only: optional boolean -- returns nothing but keys, no types,lengths,values etc. (defaults tofalse)count_amt: optional positive/non-zero integer -- redis hint for work done per SCAN operation (defaults to 10) docseach_callback: requiredfunction (type, key, subkey, length, value, next)This is called for every string, and every subkey/value in a container when not usingkeys_only, so outer keys may show up multiple times.typemay be"string","hash","set","zset","list"keyis the redis keysubkeymay benullor populated with a hash keylengthis the length of a set or listvalueis the value of the key or subkey when appropriatenext()should be called as a function with no arguments if successful or anErrorobject if not.
done_callback: optional function called when scanning completes with one argument, andErrorobject if an error ws raised
Note/Warning
If values are changing, there is no guarantee on value integrity. This is not atomic. I recommend using a lock pattern with this function.
License MIT (c) 2014 Nathanael C. Fritz