Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
RedLock is a TypeScript library for acquiring and releasing locks using Redis, designed for use in Node.js applications.
RedLock is a TypeScript library for acquiring and releasing locks using Redis, designed for use in Node.js applications.
Install the RedLock library using npm:
npm install redlock-js
To use RedLock in your Node.js application, follow these steps:
import RedLock, { LockOptions } from 'redlock-js';
const lockOptions: LockOptions = {
redis: {
host: 'localhost',
port: 6379,
},
key: 'my-lock',
interval: 100, // Optional, specify the retry interval in milliseconds
};
const redlock = new RedLock(lockOptions);
// Acquire a lock
await redlock.lock();
// Perform your critical section of code here
// Release the lock when done
await redlock.release();
You can configure RedLock by providing options when creating an instance:
redis
: Redis connection options.cluster
: If you're using a Redis cluster, provide cluster configuration.key
: The unique key for your lock.interval
(default: 100): Retry interval in milliseconds when attempting to acquire the lock.expire
(default: 300): Expiration time in seconds for the lock key. Setting an expiration time allows you to automatically release the lock after a certain duration, effectively locking a resource without needing an explicit release operation.RedLock includes an automatic cleanup function that can be used to clean up leftover lock keys. You can use the clean
method to scan and delete expired lock keys from the Redis database.
await redlock.clean();
By calling the clean
method, you can ensure that expired lock keys are removed, preventing potential issues with stale locks.
You can also check whether a lock is currently active using the isLocking
method:
const lockingStatus = await redlock.isLocking();
console.log(`Is locking: ${lockingStatus}`);
The isLocking
method returns a boolean indicating whether the lock is currently active or not.
To properly release resources and end the Redis connection, use the end
method:
await redlock.end();
Calling the end
method will gracefully close the connection to the Redis server. Additionally, when you call the release
method, the lock will be released and the associated Redis connection will be closed.
FAQs
RedLock is a TypeScript library for acquiring and releasing locks using Redis, designed for use in Node.js applications.
We found that redlock-js 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.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.