0.3.1 • Published 10 months ago

@4a/rediskit v0.3.1

Weekly downloads
1
License
MIT
Repository
github
Last release
10 months ago

RedisKit

Redis工具包

Install

npm i @4a/rediskit

Usage

// redis client需支持promise, 推荐使用ioredis
import { Redis } from 'ioredis'
import { regStock, regIncrement } from '@4a/rediskit'

const createIncr = regIncrement(new Redis())
const createStock = regIncrement(new Redis())

Stock

基于Redis简单的队列操作

createStock('app:stock:apple')
createStock('app:stock', apple)
createStock('app:stock', apple, 'price', ...)

const stock = createStock('app:stock:apple', id)

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的安全计数

createIncr('app:incr:apple')
createIncr('app:stock', apple, 'price', ...)

const increment = createIncr('app:stock:apple', id)

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

0.3.0

10 months ago

0.3.1

10 months ago

0.1.2

3 years ago

0.2.0

3 years ago

0.1.1

4 years ago

0.1.0

4 years ago