You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add a new `type` option which allows users of Redis 6.0 and newer
to scan for keys of a specific type.
- Add a new `limit` option to allow canceling a scan when we've
found the requested number of keys or more.
- Add the ability to cancel the scan via the eachScanCallback
function parameter of the eachScan() method.
- Update mocha tests and readme.
Copy file name to clipboardExpand all lines: README.md
+46-4Lines changed: 46 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,15 @@ yarn add node-redis-scan
19
19
20
20
Instantiate this class with a [Node Redis client](https://github.com/NodeRedis/node_redis) and then perform key space scans! Redis also supports scanning through hashes, sets, and sorted sets with the `HSCAN`, `SSCAN`, and `ZSCAN` commands, respectively. This functionality is available by calling the appropriately named functions listed below.
-[Canceling a scan before it has finished](#canceling-a-scan-before-it-has-finished)
30
+
22
31
### The `scan()` method
23
32
24
33
The `scan()` method provides the easiest way to scan your key space with a single callback that will be passed all matching keys. Depending on the size of your key space (millions of keys and beyond) this process might take many seconds or longer.
@@ -28,7 +37,7 @@ The `scan()` method provides the easiest way to scan your key space with a singl
28
37
|Name|Type|Description|
29
38
|-|-|-|
30
39
|`pattern`|string|The Redis glob-style string pattern to match keys against.|
31
-
|`options`|object _(optional)_|An object for configuring the precise scan parameters. Available options:<br><ul><li>`method` - String name for which underlying Redis scan method we want to use. Defaults to 'scan' and can be set to one of 'hscan', 'sscan', or 'zscan'.</li><li>`key` - The string name of the applicable key. Required if the `method` is set to 'hscan', 'sscan', or 'zscan'.</li><li>`count` - A number representing how much work Redis should do with each iteration of the given scan command. This is useful if you want to scan a huge key space faster. The trade off is lengthening the brief segments of time that Redis is locked doing work scanning. See the [Redis COUNT option documentation](https://redis.io/commands/scan#the-count-option).</li></ul>|
40
+
|`options`|object _(optional)_|An object for configuring the precise scan parameters. Available options:<br><ul><li>`method` - String name for which underlying Redis scan method we want to use. Defaults to 'scan' and can be set to one of 'hscan', 'sscan', or 'zscan'.</li><li>`key` - The string name of the applicable key. Required if the `method` is set to 'hscan', 'sscan', or 'zscan'.</li><li>`count` - A number representing how much work Redis should do with each iteration of the given scan command. This is useful if you want to scan a huge key space faster. The trade off is lengthening the brief segments of time that Redis is locked doing work scanning. See the [Redis COUNT option documentation](https://redis.io/commands/scan#the-count-option).</li><li>`type` - A string name of a Redis key type. This is used for searching for keys of a certain type. See the [Redis TYPE option documentation](https://redis.io/commands/scan#the-type-option).</li><li>`limit` - A number representing a limit for how many results should be returned. Because of the nature of the Redis SCAN command plus the interaction with the `count` option we can never guarantee returning this exact limit. When the limit is reached _or exceeded_ the scan halts and is considered complete.</li></ul>|
32
41
|`callback`|function|Invoked with (err, matchingKeys).|
33
42
34
43
**Example**
@@ -67,8 +76,8 @@ Matching keys are passed to the intermediate callback function after each iterat
67
76
|Name|Type|Description|
68
77
|-|-|-|
69
78
|`pattern`|string|The Redis glob-style string pattern to match keys against.|
70
-
|`options`|object _(optional)_|An object for configuring the precise scan parameters. Available options:<br><ul><li>`method` - String name for which underlying Redis scan method we want to use. Defaults to 'scan' and can be set to one of 'hscan', 'sscan', or 'zscan'.</li><li>`key` - The string name of the applicable key. Required if the `method` is set to 'hscan', 'sscan', or 'zscan'.</li><li>`count` - A number representing how much work Redis should do with each iteration of the given scan command. This is useful if you want to scan a huge key space faster. The trade off is lengthening the brief segments of time that Redis is locked doing work scanning. See the [Redis COUNT option documentation](https://redis.io/commands/scan#the-count-option).</li></ul>|
71
-
|`eachScanCallback`|function|Invoked with (matchingKeys).|
79
+
|`options`|object _(optional)_|An object for configuring the precise scan parameters. Available options:<br><ul><li>`method` - String name for which underlying Redis scan method we want to use. Defaults to 'scan' and can be set to one of 'hscan', 'sscan', or 'zscan'.</li><li>`key` - The string name of the applicable key. Required if the `method` is set to 'hscan', 'sscan', or 'zscan'.</li><li>`count` - A number representing how much work Redis should do with each iteration of the given scan command. This is useful if you want to scan a huge key space faster. The trade off is lengthening the brief segments of time that Redis is locked doing work scanning. See the [Redis COUNT option documentation](https://redis.io/commands/scan#the-count-option).</li><li>`type` - A string name of a Redis key type. This is used for searching for keys of a certain type. See the [Redis TYPE option documentation](https://redis.io/commands/scan#the-type-option).</li><li>`limit` - A number representing a limit for how many results should be returned. Because of the nature of the Redis SCAN command plus the interaction with the `count` option we can never guarantee returning this exact limit. When the limit is reached _or exceeded_ the scan halts and is considered complete.</li></ul>|
80
+
|`eachScanCallback`|function|This intermediate callback is used for handling matching keys as they are returned. This function can also signal cancellation of the overall scan, if desired, by returning boolean `true`.<br><br>Invoked with (matchingKeys).|
72
81
|`callback`|function|Invoked with (err, matchCount).|
// `eachZScan()` approach, which is similar to `eachScan()`
177
186
```
178
187
188
+
### Canceling a scan before it has finished
189
+
190
+
Using the `limit` option with either the `scan()` or `eachScan()` method allows us to halt or cancel a scan after a certain "limit" of matching keys have been found. Note that we might receive _more_ matching keys than the specified `limit` because of the nature of the Redis SCAN command.
0 commit comments