god-redis-kit
v0.0.2
Published
redis kit
Downloads
2
Readme
RedisKit
依赖Redis的一些常用工具
Install
npm i god-redis-kit --save
Usage
// redis client需支持promise
// 推荐使用ioredis创建redis client
const redis = require('./your-redis-client')
const { Increment } = require('god-redis-kit')(redis)
const assert = require('assert')
Increment API
Redis安全线程,后端为集群部署时常用于检查某项行为或消费是否符合预期
isRepeat
检查重复消费
const incr = Increment.create('test:Increment', 'isRepeat')
await incr.increment()
assert.ok(await incr.isRepeat(60))
isNotRepeat
检查重复消费
const incr = Increment.create('test:Increment', 'isNotRepeat')
assert.ok(await incr.isNotRepeat(1))
isOutRange
检查库存
const incr = Increment.create('test:Increment', 'isOutRange')
await incr.increment()
assert.ok(await incr.isOutRange({ max: 1 }))
isInRange
检查库存
const incr = Increment.create('test:Increment', 'isInRange')
assert.ok(await incr.isInRange({ max: 1, timeout: 1 }))
getTimes
查询消费次数
const incr = Increment.create('test:Increment', 'getTimes')
await incr.increment(1)
assert.ok(await incr.getTimes() === 1)
clear
清理消费记录
const incr = Increment.create('test:Increment', 'clear')
await incr.increment()
await incr.clear()
assert.ok(await incr.getTimes() === 0)
hasHistory
是否存在消费历史
const incr = Increment.create('test:Increment', 'hasHistory')
await incr.increment(1)
assert.ok(await incr.hasHistory())
npm test