Registry / database / passkey

passkey

JSON →
library3.0.0jsnpmunverified

passkey 3.0.0 provides a shared lock (mutex) built on top of Redis. It enables distributed locking with atomic acquire and release, automatic TTL expiration, and lock extension. Compared to alternatives, it uses Redis's atomic operations for reliability and supports promise-based API. The package is minimal, with no external dependencies beyond Redis, and is intended for Node.js environments. Release cadence is low; last major version was v3.

npm install passkey
INSTALL
IMPORT
SIG · PASSKEY
P
passkey
databasejavascriptv3.0.0
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.

passkey
import passkey from 'passkey'
const passkey = require('passkey')
In CommonJS, use require('passkey'). For TypeScript/ESM, default import works because the module has a default export.
LockError
import { LockError } from 'passkey'
import LockError from 'passkey'
LockError is a named export, not the default. It's also accessible as passkey.LockError when using CommonJS.
passkey
const passkey = require('passkey')
import passkey from 'passkey'
For CommonJS projects, use require. The default import works in ESM, but CommonJS requires require.

Shows acquiring a lock, performing work, extending TTL, and releasing, with error handling for LockError.

import redis from 'redis'; import passkey from 'passkey'; const client = redis.createClient({ url: process.env.REDIS_URL ?? '' }); await client.connect(); const key = passkey(client, { ttl: 5000 }); try { const lock = await key.lock('my-resource'); // Critical section console.log('Lock acquired'); // Optionally extend lock await lock.ttl(5000); // Release lock await lock.unlock(); } catch (err) { if (err instanceof passkey.LockError) { console.error('Lock failed or expired', err.message); } else { throw err; } } finally { await client.quit(); }
Debug
Known issues
gotchaLockError is a named export, not default. Mixing up import styles can cause runtime errors.
fix
Use import { LockError } from 'passkey' for ESM, or passkey.LockError for CommonJS.
affects: >=1.0.0
gotchaThe lock function returns a promise that resolves to a Lock instance, but if the lock cannot be acquired, it rejects with LockError. Forgetting to catch this can lead to unhandled promise rejections.
fix
Always attach .catch or use try/catch with async/await to handle LockError.
affects: >=1.0.0
gotchaThe passed Redis client must be connected before using passkey. Using an unconnected client will cause errors.
fix
Call client.connect() before passing to passkey. For redis@3.x, connection is auto; for redis@4.x, explicit connect is required.
affects: >=3.0.0
Errors
Common errors & fixes
UnhandledPromiseRejectionWarning: LockError: lock not obtained
Lock acquisition failed because the key is already locked or expired.
fix
Retry the lock with backoff or handle the error gracefully.
TypeError: client.createClient is not a function
Using import redis from 'redis' but then calling redis.createClient() incorrectly in newer redis versions.
fix
Use redis.createClient() (without 'new') and ensure the client is properly imported.
passkey is not a function
Default import used incorrectly; passkey is a default export, but some bundlers may require different syntax.
fix
Ensure you are using default import: import passkey from 'passkey'. For CommonJS: const passkey = require('passkey').
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
redisrequiredUsed for Redis client interaction; the passkey function expects a redis client instance.
Agent activity
8 hits · last 30 days
node
6
Resources
passkey — npm install passkey · libregistry