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.
@upstash/lock
Advanced tools
@upstash/lock
offers a distributed lock implementation using Upstash Redis.
NPM
npm install @upstash/lock
PNPM
pnpm add @upstash/lock
Bun
bun add @upstash/lock
To create the Redis instance, you can use the Redis.fromEnv()
method to use an Upstash Redis instance from environment variables. More options can be found here.
import { Lock } from '@upstash/lock';
import { Redis } from "@upstash/redis";
async function handleOperation() {
const lock = new Lock({
id: "unique-lock-id",
redis: Redis.fromEnv(),
});
if (await lock.acquire()) {
// Perform your critical section that requires mutual exclusion
await criticalSection();
await lock.release();
} else {
// handle lock acquisition failure
}
}
Lock
new Lock({
id: string,
redis: Redis, // ie. Redis.fromEnv(), new Redis({...})
lease?: number, // default: 10000 ms
retry?: {
attempts?: number, // default: 3
delay?: number, // default: 100 ms
},
})
Lock#acquire
Attempts to acquire the lock. Returns true
if the lock is acquired, false
otherwise.
You can pass a config
object to override the default lease
and retry
options.
async acquire(config?: LockAcquireConfig): Promise<boolean>
Lock#release
Attempts to release the lock. Returns true
if the lock is released, false
otherwise.
async release(): Promise<boolean>
Lock#extend
Attempts to extend the lock lease. Returns true
if the lock lease is extended, false
otherwise.
async extend(amt: number): Promise<boolean>
Lock#getStatus
Returns whether the lock is ACQUIRED
or FREE
.
async getStatus(): Promise<LockStatus>
Option | Default Value | Description |
---|---|---|
lease | 10000 | The lease duration in milliseconds. After this expires, the lock will be released |
retry.attempts | 3 | The number of attempts to acquire the lock. |
retry.delay | 100 | The delay between attempts in milliseconds. |
FAQs
A distributed lock implementation using Upstash Redis
The npm package @upstash/lock receives a total of 1,630 weekly downloads. As such, @upstash/lock popularity was classified as popular.
We found that @upstash/lock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.