Registry / database / redis-weighted-pool

redis-weighted-pool

JSON →
library0.2.1jsnpmunverified

A simple Promise-based weighted round-robin pool implementation using Redis sorted sets and lists. Version 0.2.1 is the latest and only release. Provides basic peer management (add, remove, getNextPeer) with configurable weights per peer. Requires a running Redis server. Written in TypeScript but compiles to JavaScript for use in ES5+ environments. Less feature-rich than alternatives like Bull, but lightweight and focused on weighted round-robin balancing.

npm install redis-weighted-pool
INSTALL
IMPORT
SIG · REDIS-WEIGHTED-POO
R
redis-weighted-pool
databasejavascriptv0.2.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.

RedisWeightedPool
import { RedisWeightedPool } from 'redis-weighted-pool'
import RedisWeightedPool from 'redis-weighted-pool'
Named export, not default.
RedisConfig
import { RedisConfig } from 'redis-weighted-pool'
const { RedisConfig } = require('redis-weighted-pool');
ESM named import; CommonJS destructuring also works but note the library exports an object of classes.
IWeightedPool
import { IWeightedPool } from 'redis-weighted-pool'
const IWeightedPool = require('redis-weighted-pool').IWeightedPool;
TypeScript interface import; not available at runtime in JavaScript.
redis-weighted-pool (CommonJS)
const pool = require('redis-weighted-pool');
const RedisWeightedPool = require('redis-weighted-pool');
The CommonJS require returns an object with RedisWeightedPool, RedisConfig etc. as properties.

Shows basic usage: create pool with Redis config, add peer with weight, get next peer using weighted round-robin.

const pool = require('redis-weighted-pool'); const config = pool.RedisConfig('localhost', 6379, null, null); const myPool = new pool.RedisWeightedPool(config); myPool.addPeer('channel1', 'peer1@example.com', 1) .then(() => console.log('Peer added')) .catch(err => console.error(err)); myPool.getNextPeer('channel1') .then(peer => console.log('Selected peer:', peer)) .catch(err => console.error(err));
Debug
Known issues
gotchaRedisConfig constructor expects (host, port, options, client) where options and client can be null; passing wrong arguments may lead to runtime errors.
fix
Only use RedisConfig for default connection; use null for client param if not providing existing client.
affects: all
gotchagetNextPeer returns a Promise that resolves to the peer ID (string) or undefined if channel is empty. Handle empty case properly.
fix
Check result for undefined or use isEmpty() before calling getNextPeer.
affects: all
gotchaaddPeer adds a peer with a given weight. Duplicate peerId in same channel may overwrite previous entry without warning.
fix
Ensure peerId uniqueness per channel, or remove before re-adding if updating weight.
affects: all
deprecatedNo known deprecation warnings; package is simple and stable.
affects: 0.2.1
Errors
Common errors & fixes
TypeError: pool.RedisConfig is not a constructor
Using pool.RedisConfig incorrectly; it's a class, not a factory function.
fix
Use new pool.RedisConfig('localhost', 6379, null, null) or use destructured imports.
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server not running or wrong host/port.
fix
Start Redis server on localhost:6379 or update RedisConfig parameters.
TypeError: Cannot read property 'length' of undefined
Calling methods on undefined pool because config was not provided correctly.
fix
Ensure RedisWeightedPool is instantiated with proper config object or null if passing client as second param.
ReferenceError: require is not defined in ES module scope
Using CommonJS require in an ES module project.
fix
Use import statements for ES modules: import { RedisWeightedPool } from 'redis-weighted-pool'
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
redisrequiredRequired for Redis operations; the library uses redis client internally.
Agent activity
4 hits · last 30 days
node
4
Resources
redis-weighted-pool — npm install redis-weighted-pool · libregistry