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();
});
});
Errors
Common errors & fixes
TypeError: redis.createClient is not a function
Passed redis client instance instead of the `redis` module as the `redis` parameter.
fixUse `{ 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).
fixEnsure pattern matches at least one key, or wrap call in a condition.
Audit
Dependencies
redisrequiredRequires a redis client instance to interact with Redis (io.redis/redis node_redis). Not bundled; user must install matching redis version.