Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Fast resource locking system based on redis.
npm install locky
import redis from "redis";
import { createClient } from "locky";
// Create a new locky client.
const locky = createClient({ redis: () => redis.createClient() });
// Lock the resource 'article:12' with the locker 20.
await locky.lock("article:12", 20);
// Refresh the lock TTL of the resource 'article:12'.
await locky.refresh("article:12");
// Unlock the resource 'article:12.
await locky.unlock("article:12");
// Get the locker of the resource 'article:12'.
await locky.getLocker("article:12");
Create a new locky client with some options.
Type: import('redis').ClientOpts | (() => import('redis').RedisClient)
If you specify an object, the properties will be used to call redis.createClient
method.
createClient({
redis: {
port: 6379,
host: "127.0.0.1",
connect_timeout: 200,
},
});
If you specify a function, it will be called to create redis clients.
import redis from "redis";
createClient({
redis: () => redis.createClient(),
});
Type: number
Define the expiration time of the lock in ms. Defaults to null
(no expiration).
const locky = createClient({ ttl: 2000 });
Type: string
, default: "locky:"
Define the prefix of every keys used by locky.
const locky = createClient({ prefix: "something:" });
Start an expiration worker, it means locky will emit "expire" events.
Lock a resource for a locker.
If the resource was already locked,
you can't lock it but by passing force: true
.
const locked = await locky.lock({
resource: "article:23",
locker: 20,
force: false,
});
// `locked` is `true` if lock has been taken, `false` if not
Type: string | number
Which resource would you like to lock.
Type: string | number
Which locker should lock the resource, can by any string.
Type: boolean
Should we take a lock if it's already locked?
Refresh the lock ttl of a resource, if the resource is not locked, do nothing.
// Refresh the resource "article:23".
locky.refresh('article:23').then(...);
Unlock a resource, if the resource is not locked, do nothing.
// Unlock the resource "article:23".
locky.unlock('article:23').then(...);
Return the locker of a resource, if the resource is not locked, return null
.
// Return the locker of the resource "article:23".
locky.getLocker('article:23').then(...);
Emitted when a resource is locked.
locky.on("lock", (resource, locker) => {
/* ... */
});
Emitted when a resource is unlocked.
locky.on("unlock", (resource) => {
/* ... */
});
Emitted when the lock on a resource has expired.
locky.on("expire", (resource) => {
/* ... */
});
MIT
FAQs
User / resource locking system.
We found that locky demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.