Registry / database / redis-delete-pattern

redis-delete-pattern

JSON →
library0.1.0jsnpmunverified

A utility to delete Redis keys matching a given pattern using the KEYS and DEL commands. Built by Uber in 2014 (v0.1.0) for batch cache invalidation. Minimal API: given a redis client instance and a glob-style pattern, it issues KEYS to find matching keys, then DEL to remove them. No updates since initial release; considered stable but unmaintained. Simpler than Lua scripting for ad-hoc purges, but inherits KEYS performance caveats on large datasets.

npm install redis-delete-pattern
INSTALL
IMPORT
SIG · REDIS-DELETE-PATTE
R
redis-delete-pattern
databasejavascriptv0.1.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.

redisDeletePattern
const redisDeletePattern = require('redis-delete-pattern');
import redisDeletePattern from 'redis-delete-pattern';
Package has no named exports; CommonJS only (default export as function). ES module import syntax will fail.
redis client
const redis = require('redis'); const client = redis.createClient();
const client = require('redis').createClient(); const redis = client;
The redis parameter expects the redis module itself (not the client instance). Passing the client object will break internal usage of `redis.createClient()`?
params.pattern
{ pattern: 'user:*' }
{ pattern: '*user*' } with leading wildcard
KEYS command is O(N) with N keys in database. Avoid patterns starting with wildcards on large DBs.

Shows installation, redis client creation, pattern deletion, and verification that non-matching keys survive.

const redis = require('redis'); const redisDeletePattern = require('redis-delete-pattern'); const client = redis.createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' }); // Set some test keys client.set('test:key1', 'value1', (err) => { if (err) console.error(err); }); client.set('test:key2', 'value2', (err) => { if (err) console.error(err); }); client.set('other:key', 'value3', (err) => { if (err) console.error(err); }); // Delete all keys matching pattern 'test:*' redisDeletePattern({ redis: redis, pattern: 'test:*' }, (err) => { if (err) { console.error('Error deleting keys:', err); process.exit(1); } // Verify deletion client.get('test:key1', (err, reply) => { console.log('test:key1 after delete:', reply); // null }); client.get('other:key', (err, reply) => { console.log('other:key after delete:', reply); // value3 client.quit(); }); });
Debug
Known issues
gotchaKEYS command blocks Redis. On large databases (>10k keys), SCAN is preferred. This library uses KEYS internally.
fix
Use a different library that uses SCAN, or implement a Lua script with SCAN + DEL.
affects: all
gotchaThe 'redis' parameter expects the redis module itself, not a client instance. Users often pass the client instead.
fix
Pass the redis module: `const redis = require('redis');` and then use it as `{ redis: redis, pattern: '...' }`.
affects: all
gotchaNo callback if pattern yields no keys: the function invokes cb with null, but inside it still calls DEL with no keys (which is harmless). No error is returned for empty set.
fix
Check for empty pattern results in your application logic if needed.
affects: all
Errors
Common errors & fixes
TypeError: redis.createClient is not a function
Passed redis client instance instead of the `redis` module as the `redis` parameter.
fix
Use `{ redis: require('redis'), pattern: '...' }` not `{ redis: client, pattern: '...' }`.
Error: ERR wrong number of arguments for 'del' command
Pattern matched no keys; DEL is called with an empty array (should still succeed on Redis 2.6+, but older versions may error).
fix
Ensure pattern matches at least one key, or wrap call in a condition.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
redisrequiredRequires a redis client instance to interact with Redis (io.redis/redis node_redis). Not bundled; user must install matching redis version.
Agent activity
11 hits · last 30 days
node
10
Resources
redis-delete-pattern — npm install redis-delete-pattern · libregistry