Code Monkey home page Code Monkey logo

redis-currents's Introduction

redis-currents

Utilities to help direct the flow of Redis streams.

// Server A
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()
// Server B, Process 1
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)
    //=> { data: 1 }
    //=> { data: 3 }
    await consumer.ack(id)
  }
}
read()
// Server B, Process 2
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)
    //=> { data: 2 }
    //=> { data: 4 }
    await consumer.ack(id)
  }
}
read()
// Server C
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)
    //=> { data: 1 }
    //=> { data: 2 }
    //=> { data: 3 }
    //=> { data: 4 }
    await consumer.ack(id)
  }
}
read()

Getting Started

Requirements

Installation

yarn add redis-currents

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.

# run all tests
yarn test

Examples

Examples in redis-currents can be found at ./examples, and run from the terminal.

yarn example:safe-exit
yarn example:groups

API

Docs generated with TypeDoc can be found at https://dvlsg.github.io/redis-currents/

redis-currents's People

Contributors

dvlsg avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.