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.
poolRedis initializer
✓ const poolRedis = require('pool-redis')({ host: 'localhost', password: '', maxConnections: 10 });
✗ const poolRedis = require('pool-redis').createPool({ host: 'localhost' });
The module exports a function that must be called with options to create a pool instance. There is no named export; it is a single default function.
getClient
✓ poolRedis.getClient(function(client, done) { /* use client */ done(); });
✗ poolRedis.getClient().then(client => { client.get('key', (err, val) => {}); });
getClient uses a callback pattern, not Promises. The second argument 'done' must be called to release the client back to the pool.
release
✓ poolRedis.release(client);
✗ poolRedis.release(client, (err) => {});
release is synchronous and does not accept a callback. It simply returns the client to the pool.
close
✓ poolRedis.close(client);
✗ poolRedis.destroy(client);
close removes and closes the client connection. There is no destroy method.
Demonstrates creating a pool, getting a client, performing SET and GET operations, releasing the client, and closing all connections.
const poolRedis = require('pool-redis')({
host: process.env.REDIS_HOST ?? 'localhost',
password: process.env.REDIS_PASSWORD ?? '',
maxConnections: 10
});
// Get a client from the pool
poolRedis.getClient(function(client, done) {
// Use the client like a normal node_redis client
client.set('key', 'value', function(err, reply) {
if (err) throw err;
console.log('SET reply:', reply);
});
client.get('key', function(err, value) {
if (err) throw err;
console.log('GET value:', value);
});
// Release the client back to the pool
done();
});
// Close all clients when done (ensure no pending operations)
setTimeout(() => {
poolRedis.closeAll();
}, 1000);
Errors
Common errors & fixes
Cannot find module 'redis'
pool-redis requires the 'redis' package but does not list it as a peer dependency.
fixRun 'npm install redis' to install the required dependency.
TypeError: poolRedis.getClient is not a function
Forgetting to call the exported function with options - poolRedis is the function itself, not a pool instance.
fixUse: const pool = require('pool-redis')({...}); then pool.getClient(...); Error: Connection closed by remote host.
Trying to use a client after it has been released back to the pool or closed.
fixEnsure all operations on a client are completed before calling done() or release().
Audit
Dependencies
redisrequiredpool-redis requires the node_redis (redis) package as a peer dependency to create and manage Redis clients.