redis-currents
Utilities to help direct the flow of Redis streams .
import { Writer } from ' redis-currents '
const writer = new Writer ( ' redis://localhost:6379 ' , ' stream_name ' )
const write = async ( ) => {
await writer . write ( { data : 1 } )
await writer . write ( { data : 2 } )
await writer . write ( { data : 3 } )
await writer . write ( { data : 4 } )
}
write ( )
import { Consumer } from ' redis-currents '
const consumer = new Consumer ( ' redis://localhost:6379 ' , ' stream_name ' , ' group_1 ' , ' consumer_1 ' )
const read = async ( ) => {
for await ( const [ id , msg ] of consumer ) {
console . log ( msg )
await consumer . ack ( id )
}
}
read ( )
import { Consumer } from ' redis-currents '
const consumer = new Consumer ( ' redis://localhost:6379 ' , ' stream_name ' , ' group_1 ' , ' consumer_2 ' )
const read = async ( ) => {
for await ( const [ id , msg ] of consumer ) {
console . log ( msg )
await consumer . ack ( id )
}
}
read ( )
import { Consumer } from ' redis-currents '
const consumer = new Consumer ( ' redis://localhost:6379 ' , ' stream_name ' , ' group_2 ' , ' consumer_1 ' )
const read = async ( ) => {
for await ( const [ id , msg ] of consumer ) {
console . log ( msg )
await consumer . ack ( id )
}
}
read ( )
Getting Started
Requirements
Installation
Tests
Tests in redis-currents
by default will assume that you have an instance of redis running locally on port 6379
.
You can override this by providing TEST_REDIS_URI
as an environment variable.
Examples
Examples in redis-currents
can be found at ./examples
, and run from the terminal.
yarn example:safe-exit
yarn example:groups