@4a/rediskit 中文文档教程
RedisKit
Redis工具包
Install
npm i @4a/rediskit
yarn add @4a/rediskit
Usage
import { Stock, Increment } from '@4a/rediskit'
Stock
基于Redis
简单的队列操作
const stock = Stock.init({ key: 'app:stock:apple', redis })
await stock.get()
await stock.set(arr, time)
await stock.save(arr, time)
await stock.prepend(item)
await stock.append(item)
await stock.pop()
await stock.shift()
await stock.remove(item)
await stock.remove(item => item.type === 1)
await stock.find(callback)
await stock.findIndex(callback)
await stock.map(callback)
await stock.each(callback)
await stock.slice(start, end)
await stock.clear()
await stock.expire()
await stock.expire(60)
Increment API
基于Redis.incr
的安全计数
const increment = Increment.init({ key: 'app:incr:apple', redis })
await increment.isRepeat()
await increment.isNotRepeat()
await increment.isOutRange(10)
await increment.isInRange(10)
await increment.isInRange(10, 3)
await increment.increment()
await increment.decrement()
await increment.clear()
await increment.expire()
await increment.expire(60)
Example
npm test