Registry / devops / node-distributed-debounce

node-distributed-debounce

JSON →
library1.0.9jsnpmunverified

A debounce function for distributed systems using Redis and Node.js. Current version 1.0.9, with no regular release cadence. It differs from client-side debounce by coordinating across multiple processes or servers via Redis, ensuring only the last invocation in a distributed environment executes the callback. Uses an atomic INCR + EXPIRE pattern for unique tickets and Redis locks for mutual exclusion. Ships TypeScript types and supports Redis clusters. Requires Node >= 10.12.0 and Redis >= 2.x as a peer dependency. Not actively maintained (last update 2019).

npm install node-distributed-debounce
INSTALL
IMPORT
SIG · NODE-DISTRIBUTED-D
N
node-distributed-debounce
devopsjavascriptv1.0.9
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.

distributedDebounce
import { distributedDebounce } from 'node-distributed-debounce'
const distributedDebounce = require('node-distributed-debounce')
The package exports a single named function. The require() pattern as shown is actually valid for CommonJS, but TypeScript projects should use import syntax for type safety.
default import
import distributedDebounce from 'node-distributed-debounce'
There is no default export. Do not attempt default import.
type import
import type { distributedDebounce } from 'node-distributed-debounce'
import { distributedDebounce } from 'node-distributed-debounce'
For type-only usage, prefer type import to avoid runtime inclusion. However, the function is needed at runtime, so use regular import for actual use.

Demonstrates distributed debounce with a Redis client, invoking the callback only for the last call in a burst across 1 second.

import { distributedDebounce } from 'node-distributed-debounce'; import redis from 'redis'; const redisClient = redis.createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379', }); async function example() { for (let i = 0; i < 10; i++) { distributedDebounce(() => { console.log('called', i); }, { wait: 5, key: 'dist:debounce:call', redisclient: redisClient, }).catch(e => console.error(e)); await new Promise(resolve => setTimeout(resolve, 100)); } } example();
Debug
Known issues
gotchaThe 'wait' parameter is in seconds, not milliseconds.
fix
Specify wait as number of seconds (e.g., 5 for 5 seconds).
affects: >=1.0.0
gotchaThe function returns a Promise that resolves when debounce completes or rejects on error. Unhandled promise rejections may crash Node processes.
fix
Always attach a .catch() or use await with try/catch.
affects: >=1.0.0
deprecatedThe package uses the 'redis' client v2.x API which is outdated. The modern 'ioredis' is not supported natively; may require adapters.
fix
Consider using ioredis with a wrapper, or stay with redis@2.x. Check compatibility before upgrading Redis client.
affects: >=1.0.0
gotchaThe key used for debounce must not conflict with other application keys in Redis, as it uses INCR and EXPIRE commands that can interfere.
fix
Use a unique prefix for your debounce keys (e.g., 'dist-debounce:').
affects: >=1.0.0
gotchaThe algorithm is not perfectly reliable under network partitions or Redis failover - it relies on a single Redis instance or cluster consistency.
fix
For critical applications, consider using Redis with sentinel or cluster mode, and implement fallback mechanisms.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or not accessible at the default host/port.
fix
Ensure Redis is running: 'redis-server' or provide correct URL via REDIS_URL env variable.
TypeError: redisclient.createClient is not a function
Incorrect import of 'redis' package: used default import where it's a namespace.
fix
Use 'import redis from 'redis'' or 'const redis = require('redis')' and then 'redis.createClient()'.
TypeError: distributedDebounce is not a function
Default import attempted instead of named import.
fix
Use correct named import: 'import { distributedDebounce } from 'node-distributed-debounce''.
Error: The 'redis' peer dependency is not installed.
The 'redis' package is missing from node_modules.
fix
Run 'npm install redis' to install the required peer dependency.
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies
redisrequiredPeer dependency: required for interacting with Redis. Must be installed separately.
Agent activity
2 hits · last 30 days
node
2
Resources
node-distributed-debounce — npm install node-distributed-debounce · libregistry