npm.io
1.4.3 • Published 9 years ago

redleaf

Licence
MIT
Version
1.4.3
Deps
6
Vulns
2
Weekly
0
Install scriptsThis package runs scripts during installation (preinstall/install/postinstall)

RedLeaf

Build Status Test Coverage Code Climate codecov npm Dependency Status Commitizen friendly

Installation

npm install redleaf

Usage

import redleaf from 'redleaf';
ZList

create a sorted set

Param Type Description
key String key of the list
server ioredis server instance of ioredis
import { ZList } from 'redleaf';
import Redis from 'ioredis';

const redisServer = new Redis();
const list = new ZList('listKey', redisServer)
list.add({ score, member }) => Promise<0|1>

ZADD

Param Type Description
score Number score of member
member String value to add on list
list.add({
	member: 'one',
	score: 1,
	})
list.add({
	member: 'two',
	score: 2,
	})
score(member) => Promise< Number >

ZSCORE

Param Type Description
member String value to ask for its score
list.score('one') // 1
list.scrose('three') // -1
remove(member) => Promise<1|2>

ZREM

Param Type Description
member String value to remove from set
list.remove('one') // 1
list.remove('four') // 0
scan(cursor) => Promise< {pointer: String, data: [{ member, score }] } >

ZSCAN

Param Type Description
cursor String to iterate over set
rangeByScore(ops) => Promise<[{ member, score }]>

ZRANGEBYSCORE

ZREVRANGEBYSCORE

Param Type Default Description
[ops] String {}
[ops.range] String {} range to get the items
[ops.range.min] String "-inf" score minimun to get items
[ops.range.max] String "+inf" score maximun to get items
[ops.limit] String ammount max to bring on request
[ops.reverse] Boolean false to use ZREVRANGEBYSCORE or not
list.rangeByScore() // [ {member: 'one', score: 1 }, { member: 'two', score: 2 }]
list.rangeByScore({
	range: {
		min: 1,
		max: 5
	},
	limit: 1,
	reverse: true
}); // [ { member: 'two', score: 2 }]

Features to have

License: MIT