Skip to content

Commit 5ad3edb

Browse files
committed
Add options object to keys signature with optional scanCount.
1 parent ddfca86 commit 5ad3edb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,19 @@ function redisStore(args) {
328328
* Returns all keys matching pattern using the SCAN command.
329329
* @method keys
330330
* @param {String} pattern - The pattern used to match keys
331+
* @param {Object} [options] - The options (optional)
332+
* @param {number} [options.scanCount] - The number of keys to traverse with each call to SCAN (default: 100)
331333
* @param {Function} cb - A callback that returns a potential error and the response
332334
*/
333-
self.keys = function(pattern, cb) {
335+
self.keys = function(pattern, options, cb) {
334336
if (typeof pattern === 'function') {
335337
cb = pattern;
336338
pattern = '*';
339+
options = {};
340+
}
341+
else if (typeof options === 'function') {
342+
cb = options;
343+
options = {};
337344
}
338345

339346
connect(function(err, conn) {
@@ -343,10 +350,10 @@ function redisStore(args) {
343350

344351
// Use an object to dedupe as scan can return duplicates
345352
var keysObj = {};
346-
var count = 100;
353+
var scanCount = options.scanCount || 100;
347354

348355
(function nextBatch(cursorId) {
349-
conn.scan(cursorId, 'match', pattern, 'count', count, function (err, result) {
356+
conn.scan(cursorId, 'match', pattern, 'count', scanCount, function (err, result) {
350357
if (err) {
351358
return cb && cb(err);
352359
}

0 commit comments

Comments
 (0)