|
1 | 1 | redis-key-scanner |
2 | 2 | ================= |
3 | 3 |
|
4 | | -Scan a redis server for keys matching specified criteria, including key |
5 | | -patterns, TTL and IDLETIME. Selected/matched keys are output in a JSON log |
6 | | -format. The scan is non-destructive, and doesn't even read any actual key |
7 | | -values. |
8 | | - |
9 | | -Note that if you are checking TTL times, due to an acknowledged |
10 | | -[bug][redis-ttl-bug] in Redis, this will actually reset the IDLETIME to 0 for |
11 | | -the selected keys, so subsequent scans may not return the same results. |
12 | | - |
13 | | -Example command-line usage, querying a locally running redis server for keys |
14 | | -that start with the prefix "mykeys:" and have been idle (ie., not written or |
15 | | -read) for at least one week: |
| 4 | +Scan a redis server for keys matching specified criteria, including key patterns, TTL and IDLETIME. |
| 5 | +Selected/matched keys are output in a JSON log format. The scan is non-destructive, and doesn't |
| 6 | +even read any actual key values. |
| 7 | + |
| 8 | +Note that if you are checking TTL times, due to an acknowledged [bug][redis-ttl-bug] in Redis, this |
| 9 | +will actually reset the IDLETIME to 0 for the selected keys, so subsequent scans may not return the |
| 10 | +same results. |
| 11 | + |
| 12 | +Example command-line usage, querying a locally running redis server for keys that start with the |
| 13 | +prefix "mykeys:" and have been idle (ie., not written or read) for at least one week: |
16 | 14 | ``` |
17 | 15 | > npm install -g redis-key-scanner |
18 | 16 | > redis-key-scanner localhost --pattern=mykeys:* --min-idle=1w |
19 | 17 | ``` |
20 | 18 |
|
21 | | -Output will be one JSON line per selected key, followed by a "summary" line with |
22 | | -total stats: |
| 19 | +Output will be one JSON line per selected key, followed by a "summary" line with total stats: |
23 | 20 | ``` |
24 | 21 | {"name":"localhost:6379","key":"mykeys:larry","idletime":604800} |
25 | 22 | {"name":"localhost:6379","key":"mykeys:curly","idletime":900000} |
26 | 23 | {"name":"localhost:6379","key":"mykeys:moe","idletime":1000000} |
27 | 24 | {"keysScanned":17,"keysSelected":3,"host":"localhost","port":6379,"scanBatch":1000,"scanLimit":null,"limit":null,"pattern":"mykeys:*"} |
28 | 25 | ``` |
29 | 26 |
|
30 | | -You can alternatively require `redis-key-scanner` as a Node.js module, in which |
31 | | -case it implements a stream interface and each record will be emitted as a |
32 | | -separate 'data' event. |
| 27 | +You can alternatively require `redis-key-scanner` as a Node.js module, in which case it implements a |
| 28 | +stream interface and each record will be emitted as a separate 'data' event. |
33 | 29 | ```js |
34 | | -var RedisKeyScanner = require('redis-key-scanner'); |
35 | | -var scanner = new RedisKeyScanner({ |
| 30 | +const RedisKeyScanner = require('redis-key-scanner'); |
| 31 | +const scanner = new RedisKeyScanner({ |
36 | 32 | host: 'localhost', |
37 | 33 | pattern: 'mykeys:*', |
38 | 34 | minIdle: '1w' |
39 | 35 | }); |
40 | | -scanner.on('data', function(data) { |
| 36 | +scanner.on('data', (data) => { |
41 | 37 | console.log(data); |
42 | 38 | }); |
43 | | -scanner.on('end', function() { |
| 39 | +scanner.on('end', () => { |
44 | 40 | // clean up |
45 | 41 | }); |
46 | 42 | ``` |
47 | 43 |
|
48 | | -Run `node redis-key-scanner` to see the full list of available options. |
| 44 | +Run `redis-key-scanner` to see the full list of available options. |
49 | 45 |
|
50 | 46 |
|
51 | 47 | [redis-ttl-bug]: https://github.com/antirez/redis/pull/2090#issuecomment-75944263 |
0 commit comments