Registry / storage / redis-scanstreams

redis-scanstreams

JSON →
library1.0.3jsnpmunverified

A streaming interface for Redis SCAN, SSCAN, HSCAN, and ZSCAN commands. Version 1.0.3 (last updated in 2017). It monkey-patches the node_redis client's *SCAN methods to return Node.js streams (Readable) instead of using callbacks, enabling easier consumption via pipe or stream libraries like terminus. This package is specific to node_redis and does not work with ioredis. It has no active maintenance and no TypeScript definitions. Suitable for scanning large datasets without blocking the event loop, but consider alternatives like ioredis which includes built-in scan streams.

npm install redis-scanstreams
INSTALL
IMPORT
SIG · REDIS-SCANSTREAMS
R
redis-scanstreams
storagejavascriptv1.0.3
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
require('redis-scanstreams')(redis)
import redisScanstreams from 'redis-scanstreams'
Package does not export a named symbol; it exports a single function that must be called with the redis module. ESM import is not supported; use require() or const redisScanstreams = require('redis-scanstreams'); redisScanstreams(redis);
client.scan()
client.scan({pattern: 'key:*', count: 100})
client.scan('0', 'MATCH', 'key:*', 'COUNT', 100)
The patched scan() method accepts an options object, not raw Redis arguments. Returns a readable stream, not a callback.
client.sscan()
client.sscan('myset', {pattern: 'item:*'})
client.sscan('myset', '0', 'MATCH', 'item:*')
Returns a stream of set members (strings).
client.hscan()
client.hscan('myhash', {pattern: 'field:*'})
client.hscan('myhash')
Returns a stream of objects with keys 'key' and 'value' for each hash field.
client.zscan()
client.zscan('myzset', {pattern: 'member:*'})
client.zscan('myzset', '*', 'COUNT', 10)
Returns a stream of objects with keys 'key' (member) and 'value' (score).

Patches node_redis client to use streaming SCAN, logs matched keys.

const redis = require('redis'); require('redis-scanstreams')(redis); const client = redis.createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' }); client.scan({ pattern: '*', count: 100 }) .on('data', (key) => console.log(key)) .on('end', () => client.quit());
Debug
Known issues
gotchaMonkey-patches the global redis client prototype. All clients created after the patch will have streaming *SCAN methods.
fix
Apply the patch early in your application before creating any redis clients, or be aware that existing clients are not affected.
affects: >=0.0.0
gotchaOnly works with node_redis (redis npm package). Does not support ioredis or other Redis clients.
fix
Use ioredis which has built-in scan streams, or use node_redis.
affects: >=0.0.0
deprecatedPackage is in maintenance mode, last updated in 2017. No TypeScript definitions, no ESM support, no active development.
fix
Consider using ioredis with its built-in scanStream() methods for better performance and maintenance.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: redis.scan is not a function
require('redis-scanstreams') was called but the redis library was not patched correctly.
fix
Ensure you call require('redis-scanstreams')(redis) before creating a client.
Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED
Redis server is not running or is unreachable.
fix
Start Redis server or set the REDIS_URL environment variable to a valid connection string.
TypeError: Destructuring `key` and `value` from scan results fails
hscan and zscan streams emit objects of shape {key, value}, but users may try to destructure as separate values.
fix
Use .on('data', ({key, value}) => ...) or .map(({key, value}) => ...).
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
redisrequiredpeer dependency: requires node_redis client to patch its *SCAN methods
Agent activity
23 hits · last 30 days
node
22
Resources
redis-scanstreams — npm install redis-scanstreams · libregistry