@wenye123/redis-lock
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

redis-lock

Build Status Coverage Status npm npm

简单的 redis 分布式锁

安装

npm i -S @wenye123/redis-lock

使用例子

import redisLock from "@wenye123/redis-lock";
import Redis from "ioredis";

const redis = new Redis({
  host: "127.0.0.1",
  port: 6379,
});

const rlock = new redisLock({
  client: redis,
  keyPrefix: "bm:",
});

const lockName = "tlock";
// 获取锁标志,null则表示获取失败
const identifier = await rlock.acquireLock(lockName);
// 释放锁
await rlock.releaseLock(lockName, identifier as string);

const sename = "tsename";
// 获取信号量
const identifier = await rlock.acquireSemaphore(sename, 1);
// 刷新信号量
await rlock.refreshSemaphore(sename, identifier as string);
// 释放信号量
await rlock.releaseSemaphore(sename, identifier as string);

Package Sidebar

Install

npm i @wenye123/redis-lock

Weekly Downloads

1

Version

1.0.4

License

MIT

Unpacked Size

9.25 kB

Total Files

5

Last publish

Collaborators

  • wenye123