Registry / database / redisscan

redisscan

JSON →
library2.0.0jsnpmunverified

redisScan (v2.0.0) recursively iterates over all keys in a Redis instance using the recommended SCAN family of commands (SCAN, HSCAN, SSCAN, ZSCAN) and lists. It avoids the blocking KEYS * command, making it production-safe. Supports optional pattern matching and a callback per key or container element. Released as a single-version package with low update cadence. Differentiates from similar tools by supporting all data structures and providing detailed type/key/subkey/value info for each element.

npm install redisscan
INSTALL
IMPORT
SIG · REDISSCAN
R
redisscan
databasejavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (function)
const redisScan = require('redisscan');
import redisScan from 'redisscan';
Package uses CommonJS; ESM import will fail unless using default interop.
default (function) via ESM
import redisScan from 'redisscan';
import { redisScan } from 'redisscan';
Named import does not exist; must import default.
TypeScript usage (no types shipped)
// @ts-ignore const redisScan = require('redisscan');
import redisScan from 'redisscan'; (no type definitions)
Package has no TypeScript declarations; use require with @ts-ignore or create your own types.

Initialize Redis client, scan all keys matching 'user:*', log each value, then quit.

const redis = require('redis').createClient(); const redisScan = require('redisscan'); redisScan({ redis: redis, pattern: 'user:*', keys_only: false, each_callback: function(type, key, subkey, length, value, cb) { console.log(`Type: ${type}, Key: ${key}, Subkey: ${subkey}, Length: ${length}, Value: ${value}`); cb(); }, done_callback: function(err) { if (err) console.error('Scan error:', err); console.log('Scan complete'); redis.quit(); } });
Debug
Known issues
gotchaeach_callback is required even if keys_only: true; the function is still called for each key but with simplified arguments.
fix
Provide an each_callback that accepts the correct arguments (type, key, subkey, length, value, cb).
affects: >=2.0.0
gotchadone_callback will not be called if an error occurs during scanning; the error is only passed as the first argument to done_callback. If each_callback passes an Error to next(), the scan stops and done_callback receives that error.
fix
Check for err in done_callback; if an error occurs, it will be passed there.
affects: >=2.0.0
gotchaThe package does not support Promises or async/await; callbacks only.
fix
Use callbacks or promisify with util.promisify() (but note the multiple callbacks pattern may not promisify cleanly).
affects: >=2.0.0
gotchacount_amt defaults to 10; increasing it may improve performance but uses more memory per cursor iteration.
fix
Adjust count_amt based on expected number of keys and available memory.
affects: >=2.0.0
gotchaIf keys are added/removed during scan, the iteration may not reflect a consistent snapshot (non-atomic).
fix
Use a Redis lock pattern to ensure consistency if needed.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: redisScan is not a function
Using named import instead of default import (e.g., import { redisScan } from 'redisscan').
fix
Use default import: const redisScan = require('redisscan'); or import redisScan from 'redisscan';
TypeError: done_callback is not a function
Calling redisScan() without providing a done_callback, or providing a non-function value.
fix
Provide a function for done_callback, or omit it entirely (it's optional).
Error: each_callback is required
Missing each_callback in the options object.
fix
Add each_callback function to the options.
TypeError: redis.createClient is not a function
Using a newer version of node-redis (v4+) where createClient is not the same signature.
fix
Use redis.createClient() from node-redis version 3.x, or adapt to v4+ (which returns a promise).
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
redisrequirednode-redis client instance required for connection
Agent activity
6 hits · last 30 days
node
6
Resources
redisscan — npm install redisscan · libregistry