davidyaha / graphql-redis-subscriptions

A graphql subscriptions implementation using redis and apollo's graphql-subscriptions
MIT License
1.11k stars 125 forks source link

feat: Add pipeline support for batching multiple publish calls #630

Open jgillick opened 1 month ago

jgillick commented 1 month ago

If a large number of publish calls need to be made, they call all be batched into a single HTTP request to redis with a pipeline.

This PR attempts to keep to keep the familiar redis pipelining API while supporting the PubSub config and serializer.

Basic Example

If you have a list to publish:

const pubSub = new RedisPubSub({ ... });

// Create pipeline
const pipeline = pubSub.pipeline();

[1,2,3,4,5,6].forEach((id) => pipeline.publish('Test', {id}))

// Execute the pipeline to redis
await pipeline.exec();

Chainable calls

If you have a specific number of publish calls to make at the same time:

const pubSub = new RedisPubSub({ ... });
await pubSub
  .pipeline()
  .publish('Test1', {})
  .publish('Test2', {})
  .publish('Test3', {})
  .exec();