Registry / database / redis-connection-pool

redis-connection-pool

JSON →
library4.0.1jsnpmunverified

A connection pooling library for Redis in Node.js, version 4.0.1. It manages a configurable number of Redis connections internally, distributing requests across available connections and handling release automatically. This package wraps the popular 'redis' client library and exposes a simplified subset of Redis commands (get, set, hgetall, lpush, etc.) plus a sendCommand method for arbitrary commands. It is TypeScript-ready with full type definitions. Release cadence is low (sporadic) but the API is stable. Compared to manual pool management, this library abstracts all acquisition and release logic, reducing boilerplate and common errors like forgetting to return connections.

npm install redis-connection-pool
INSTALL
IMPORT
SIG · REDIS-CONNECTION-P
R
redis-connection-pool
databasejavascriptv4.0.1
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 (factory function)
✓ import redisPoolFactory from 'redis-connection-pool'
✗ import { redisPoolFactory } from 'redis-connection-pool'
The package exports a default export that is a factory function. Named import will result in undefined.
RedisConnectionPool class
✓ import RedisConnectionPool from 'redis-connection-pool'
✗ import { RedisConnectionPool } from 'redis-connection-pool'
The class is also the default export (the factory is the default, but the class itself is accessible via default export). Named import will not work. Use 'new RedisConnectionPool()' after importing the default.
CommonJS require
✓ const redisPoolFactory = require('redis-connection-pool')
✗ const { redisPoolFactory } = require('redis-connection-pool')
In CommonJS, the default export is assigned to module.exports, so destructuring will fail. Use default require.

Creates a Redis connection pool, sets and gets a key, executes a custom command via sendCommand, and shuts down the pool.

import redisPoolFactory from 'redis-connection-pool'; // Create a pool with 3 max clients, connecting to localhost const redisPool = await redisPoolFactory('myPool', { max_clients: 3, redis: { url: process.env.REDIS_URL || 'redis://localhost:6379' } }); // Use standard Redis commands await redisPool.set('user:1000:name', 'Alice'); const name = await redisPool.get('user:1000:name'); console.log(name); // Alice // Use sendCommand for any other Redis command const info = await redisPool.sendCommand('INFO', ['server']); console.log(info); // Clean up when done redisPool.shutdown();
Debug
Known issues
breakingIn version 4.0.0, the underlying 'redis' client was upgraded from v3 to v4. This change is breaking because v4 switched from callbacks to promises and changed the configuration format.
fix
Update to >=4.0.0 and adapt configuration: replace 'host'/'port' options with 'url' or 'socket' object. Also ensure your code uses async/await or promises instead of callbacks.
affects: <4.0.0
breakingThe factory function is now async in v4.0.0+ (returns a Promise). Previously it was synchronous.
fix
Await the call to redisPoolFactory or use .then(). Old code that assigned the result synchronously will receive a Promise instead of the pool object.
affects: <4.0.0
gotchaThe pool's shutdown() method does not wait for pending operations to complete before closing connections. In-flight commands may fail with 'Connection closed' errors.
fix
Ensure all commands have resolved before calling shutdown, e.g., by awaiting all your Redis calls or using a counter.
affects: >=4.0.0
gotchaDefault export is a factory function, not the class. Using new default() will fail because the default is not a constructor.
fix
Call the default export as a function (with await) or import the class directly (import RedisConnectionPool from 'redis-connection-pool').
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: redisPool.get is not a function
The default import is a factory function returning a Promise, not the pool itself. Code that calls factory without await gets a Promise, not a pool.
fix
Use await: const redisPool = await redisPoolFactory('pool', options);
Error: The client is closed
Attempting to use the pool after shutdown() has been called, or the underlying Redis connection dropped.
fix
Ensure you are not using the pool after shutdown. Check your Redis server availability and network.
TypeError: redisPool.sendCommand is not a function
Using an older version (<4.0.0) where sendCommand was not exposed as a method. Or the pool was not initialized properly.
fix
Upgrade to >=4.0.0 and ensure the pool is correctly initialized. sendCommand was added in v4.
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
redisrequiredUnderlying Redis client dependency (v4.x). Required for all Redis operations.
Agent activity
11 hits · last 30 days
node
10
Resources
redis-connection-pool — npm install redis-connection-pool · libregistry