Registry / database / redis-connection

redis-connection

JSON →
library5.4.0jsnpmunverified

A global Redis connection manager for Node.js that reuses a single connection (or pair for Pub/Sub) across modules. Current stable version is 5.4.0. Released with moderate cadence. Differentiators: automatically manages connection lifecycle, supports both standard and subscriber connections, and simplifies test cleanup by allowing a single close call. Provides a singleton pattern to avoid exhausting Redis connection limits.

npm install redis-connection
INSTALL
IMPORT
SIG · REDIS-CONNECTION
R
redis-connection
databasejavascriptv5.4.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 (connection)
const redisClient = require('redis-connection')();
require('redis-connection') as a constructor without calling
Must call the exported function to get a connection. CommonJS only; the package does not support ESM imports.
subscriber connection
const redisSub = redisClient.get('default')
require('redis-connection')('subscriber')
No official subscriber export; the readme shows require('redis-connection')('subscriber') but that is not actually supported. Use redisClient.duplicate() instead.
closing
redisClient.end(true)
redisClient.quit()
Use end(true) to flush pending commands. quit() may not close all connections.

Demonstrates creating a global Redis connection, performing basic set/get, and closing the connection.

const redisClient = require('redis-connection')(); redisClient.set('hello', 'world'); redisClient.get('hello', (err, reply) => { console.log('hello', reply.toString()); // hello world redisClient.end(true); });
Debug
Known issues
deprecatedThe underlying 'redis' package v3.x is deprecated. Upgrade to 'redis' v4+ and adapt code (promises, breaking API changes).
fix
Switch to 'redis' v4 client: import { createClient } from 'redis'; const client = createClient(); await client.connect();
affects: >=5.0.0 <6.0.0
breakingCalling require('redis-connection')('subscriber') does not create a separate subscriber connection as documented.
fix
Use redis.duplicate() with client.duplicate() to create a subscriber connection.
affects: >=5.0.0
gotchaPackage does not support ESM (EcmaScript Modules). Requires CommonJS require().
fix
Use dynamic import() if needed, but prefer CommonJS require() or switch to a modern Redis client library.
affects: >=5.0.0
gotchaThe global connection is singleton; calling require('redis-connection')() multiple times returns the same connection. This can lead to unintended shared state.
fix
Understand that it's a singleton. If you need multiple connections, manage them manually with 'redis' directly.
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: redisClient.set is not a function
Using the package with ESM import (import redisClient from 'redis-connection') without calling the default export function.
fix
Use CommonJS: const redisClient = require('redis-connection')(); then call the function.
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or not accessible at default host/port.
fix
Start Redis server: redis-server, or configure REDIS_URL environment variable pointing to your Redis instance.
DeprecationWarning: The 'redis' package is deprecated. Please use 'redis' v4 or higher.
The underlying 'redis' v3 is deprecated.
fix
Upgrade your project to use 'redis' v4 directly. Replace require('redis-connection') with import { createClient } from 'redis'.
Upgrade
Version history
5.4.0latest on npm
Audit
Dependencies
redisrequiredUnderlying Redis client used for all operations.
Agent activity
14 hits · last 30 days
node
12
Amazon
1
Resources
redis-connection — npm install redis-connection · libregistry