@zaeny/redis
v1.1.9
Published
Utility functions wrap redis node.js driver
Downloads
354
Readme
@zaeny/redis
Redis functions
wrap redis node.js driver expose command function and parse returned if json command specific
Getting Started
npm i @zaeny/redis
Usage
parsing json data automaticly, both input json and output json
process.env.REDIS_URL="redis://redisuser:[email protected]:6379"
var client = createRedis(process.env.REDIS_URL);
connectRedis(client)
command(['ping'], client).then(console.log)
command(['json.get', 'foo', '$.data'], client)
command(['json.set', 'foo', '$', {data: 1}], client)
command(['json.mget', 'foo', 'bar', '$'], client)
blocking read and stream reading
reader(['xreadgroup', 'mystream', 'group1', 'consumer1', '100', '0', '0'], (data)=> console.log(data), rs);
reader(['xread', 'mystream', '100', '0', '0'], (data)=> console.log(data), rs);
command(['xadd', 'mystream', {data: '1'}], rs)
command(['xadd', 'mystream', ['data', '1']], rs);
closing stream
var mystream = reader(['xread', 'mystream', '100', '0', '0'], (data)=> console.log(data), rs);
mystream.close();
add acknowledge
// ack([streamId]);
var processStream = ((data, ack) =>{
ack(map(first, data));
console.log(data);
}
reader(['xreadgroup', 'mystream', 'group1', 'consumer1', '100', '0', '0'], processStream, rs);
var mystream = reader(['xread', 'mystream', '100', '0', '0'], (data)=> console.log(data), rs);
API
createRedis,
connectRedis,
command,
reader,
parsePair,
Related work
- Composable - Collection of functions to solve programming problem
Changes
- [1.0.0] add
command
and basic parsing json - [1.0.1] add blocking
reader
to support basicxread
andxreadgroup
- [1.0.2] add
parsePair
parsing tupple return from redis into object js - [1.0.3] fix
parsePair
isEven
is not defined - [1.0.4] add
retry_strategy
reconnecting, addtfload
,tfcall
- [1.0.5] fix json.get return array
- [1.0.6] fix multiple path
$.[]
at json.get - [1.0.7] move to new repositoy, add
xack
- [1.1.2] add new stream acknowledge
- [1.1.3] fix repository homepage
- [1.1.4] fix the parse value for
json.mget
- [1.1.5] add
createClusterRedis
- [1.1.6] add support
command
in cluster mode, supportisReadonly
command - [1.1.7] add simple replication routing, use weight distribution
- [1.1.8] add fix for duplicate client for
reader
command - [1.1.9] add support for sending string
command