Registry / database / redis-clients

redis-clients

JSON →
library0.5.2jsnpmunverified

redis-clients is a Node.js library providing factory functions for creating Redis clients, publishers, and subscribers with optional key prefixing and separator configuration. Current stable version is 0.5.2, last updated in 2019. It wraps the standard redis package (node_redis) and adds convenience methods like count(), clear(), and key() for pattern-based operations. Differentiators include built-in support for pub/sub client pairs and automatic key prefixing. Release cadence is low; the package is mature but receives minimal updates.

npm install redis-clients
INSTALL
IMPORT
SIG · REDIS-CLIENTS
R
redis-clients
databasejavascriptv0.5.2
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
import redis from 'redis-clients';
const redis = require('redis-clients');
Library supports both ESM imports and CommonJS require. Use ESM for modern Node.js projects.
publisher
const { publisher } = redis.pubsub();
const publisher = redis.pubsub().publisher;
pubsub() returns an object with publisher and subscriber properties. Destructure for clarity.
subscriber
const { subscriber } = redis.pubsub();
const subscriber = redis.pubsub().subscriber;
Same note as publisher.

Shows initialization with options, basic set/get, pub/sub usage, and pattern-based clear. Uses environment variables for Redis connection.

import redisFactory from 'redis-clients'; const redis = redisFactory({ prefix: 'app', separator: ':', redis: { host: process.env.REDIS_HOST || 'localhost', port: parseInt(process.env.REDIS_PORT || '6379') } }); const client = redis.client(); client.set('user:123', JSON.stringify({ name: 'Alice' })); client.get('user:123', (err, reply) => { if (err) console.error(err); else console.log('User:', JSON.parse(reply)); }); const { publisher, subscriber } = redis.pubsub(); subscriber.subscribe('updates'); subscriber.on('message', (channel, message) => { console.log(`Received on ${channel}: ${message}`); }); redis.clear('user*', (err, responses) => { if (err) console.error(err); else console.log('Cleared keys:', responses); }); redis.quit();
Debug
Known issues
deprecatedThe redis package used internally (node_redis) has been deprecated in favor of ioredis. New projects should use ioredis directly.
fix
Switch to ioredis or ioredis-based alternatives. This package is unlikely to receive updates.
affects: >=0.1.0
gotchaThe module returns a factory function when called with options; omitting options returns a default instance.
fix
Always pass options even if empty object: const redis = require('redis-clients')({});
affects: >=0.1.0
gotchaMethods like count() and clear() with callbacks do not return Promises. Use promisify or wrap calls.
fix
Use util.promisify: const [pCount, pClear] = [redis.count, redis.clear].map(f => promisify(f.bind(redis)));
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: redis.client is not a function
Forgetting to invoke the default export as a factory function
fix
Use const redis = require('redis-clients')(); or import redis from 'redis-clients'; const r = redis();
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server not running or wrong host/port
fix
Start Redis server or specify correct connection in options: { redis: { host: 'your-host', port: 6379 } }
TypeError: redis.count is not a function
Using the factory function directly instead of the initialized instance
fix
Call the default export first: const redis = require('redis-clients')(); then use redis.count()
Upgrade
Version history
0.5.2latest on npm
Audit
Dependencies
redisrequiredCore Redis client library used for all Redis operations
Agent activity
11 hits · last 30 days
node
8
Meta
1
Resources
redis-clients — npm install redis-clients · libregistry