
Research
/Security News
PolinRider Spreads Through Compromised GitHub Accounts and Packagist
Operators behind PolinRider used a compromised GitHub account to plant malware in four development versions of a Packagist package with 700,000+ downloads.
redlock-toolkit
Advanced tools
Advanced Redis distributed locking library with Redlock algorithm, Circuit Breaker pattern, automatic extension and optimistic locking support
Redlock Toolkit is a powerful TypeScript library for distributed locking that implements the Redlock algorithm with advanced features for fault tolerance, monitoring, and performance.
npm install redlock-toolkit
import RedlockToolkit from 'redlock-toolkit';
import Redis from 'ioredis';
// Create Redis clients
const clients = [
new Redis({ host: 'redis1.example.com', port: 6379 }),
new Redis({ host: 'redis2.example.com', port: 6379 }),
new Redis({ host: 'redis3.example.com', port: 6379 })
];
// Initialize Redlock Toolkit
const redlockToolkit = new RedlockToolkit({
clients,
defaultLockOptions: {
ttl: 30000, // 30 seconds
retryCount: 10, // 10 attempts
retryDelay: 200, // 200ms delay
retryJitter: 100 // ±100ms jitter
}
});
// Basic usage
async function basicExample() {
try {
// Acquire lock
const lock = await redlockToolkit.acquire('user:123');
// Perform critical section
await performCriticalWork();
// Release lock
await lock.release();
} catch (error) {
console.error('Lock operation failed:', error);
}
}
// Using automatic lock management
async function autoManagedExample() {
const result = await redlockToolkit.using(
'payment:order:456',
async (signal) => {
// Check for abort
if (signal.aborted) throw signal.error;
// Your critical code here
const result = await processPayment();
// Lock is automatically extended and released
return result;
},
{
ttl: 60000,
autoExtendThreshold: 5000
}
);
}
// Acquire with version control
const result = await redlockToolkit.acquireOptimistic('document:789', {
expectedVersion: 0,
ttl: 30000
});
if (result.success) {
// Update with conflict detection
const updateResult = await redlockToolkit.updateOptimistic(
'document:789',
result.currentVersion!,
{
expectedValue: { status: 'processing' }
}
);
}
// Combine optimistic and pessimistic approaches
const lock = await redlockToolkit.acquireHybrid('inventory:item:123', {
primaryStrategy: 'optimistic',
fallbackStrategy: 'pessimistic',
expectedVersion: 0,
ttl: 30000
});
const redlockToolkit = new RedlockToolkit({
clients,
circuitBreaker: {
failureThreshold: 5, // Open circuit after 5 failures
resetTimeout: 60000, // Try to recover after 60 seconds
maxRetries: 3, // Maximum retries in half-open state
operationTimeout: 5000 // Operation timeout
}
});
// Get current metrics
const metrics = redlockToolkit.getMetrics();
console.log(`Active locks: ${metrics.activeLocks}`);
console.log(`Success rate: ${metrics.locksAcquired / metrics.failedAcquisitions}`);
// Export Prometheus metrics
const prometheusMetrics = redlockToolkit.exportMetrics();
// Get performance summary
const summary = redlockToolkit.getPerformanceSummary();
console.log(`Average acquisition time: ${summary.averageAcquisitionTime}ms`);
redlockToolkit.on('lock:acquired', (resources, identifier) => {
console.log(`Lock acquired: ${resources.join(', ')}`);
});
redlockToolkit.on('lock:failed', (resources, error) => {
console.error(`Lock failed: ${error.message}`);
});
redlockToolkit.on('circuit:stateChanged', (newState) => {
console.log(`Circuit breaker state: ${newState}`);
});
The library implements the Redlock algorithm as described in the Redis documentation:
interface RedlockToolkitConfig {
clients: RedisClient[]; // Redis client instances
defaultLockOptions?: {
ttl?: number; // Lock time-to-live (ms)
retryCount?: number; // Number of retry attempts
retryDelay?: number; // Base retry delay (ms)
retryJitter?: number; // Random jitter (ms)
driftFactor?: number; // Clock drift factor
autoExtendThreshold?: number; // Auto-extend threshold (ms)
};
circuitBreaker?: CircuitBreakerConfig; // Circuit breaker settings
enableMetrics?: boolean; // Enable metrics collection
keyPrefix?: string; // Redis key prefix
}
| Operation | Avg Time | Throughput |
|---|---|---|
| Acquire (3 nodes) | 2.5ms | 400 ops/s |
| Release | 1.2ms | 830 ops/s |
| Extend | 1.8ms | 555 ops/s |
| With Auto-Extension | 3.1ms | 320 ops/s |
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run specific test suite
npm test -- --grep "circuit breaker"
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
# Clone repository
git clone https://github.com/x51xxx/redlock-toolkit.git
cd redlock-toolkit
# Install dependencies
npm install
# Run tests
npm test
# Build
npm run build
This project is licensed under the MIT License - see the LICENSE file for details.
redlock-toolkitBuilt with ❤️ by Taras Trishchuk
FAQs
Advanced Redis distributed locking library with Redlock algorithm, Circuit Breaker pattern, automatic extension and optimistic locking support
We found that redlock-toolkit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.

Research
/Security News
Operators behind PolinRider used a compromised GitHub account to plant malware in four development versions of a Packagist package with 700,000+ downloads.

Security News
GitHub Actions now supports cache-mode, a least-privilege control on the Actions cache aimed at the cache poisoning technique behind recent compromises.

Company News
Allow myself to introduce... myself.