npm @socket.io/redis-adapter 8.2.0

latest releases: 8.3.0, 8.2.1
12 months ago

Bug Fixes

  • cleanup error handler to prevent memory leak (#490) (b5da02d)

Features

Sharded Pub/Sub

Sharded Pub/Sub was introduced in Redis 7.0 in order to help scaling the usage of Pub/Sub in cluster mode.

Reference: https://redis.io/docs/manual/pubsub/#sharded-pubsub

A dedicated adapter can be created with the createShardedAdapter() method:

import { Server } from 'socket.io';
import { createClient } from 'redis';
import { createShardedAdapter } from '@socket.io/redis-adapter';

const pubClient = createClient({ host: 'localhost', port: 6379 });
const subClient = pubClient.duplicate();

await Promise.all([
  pubClient.connect(),
  subClient.connect()
]);

const io = new Server({
  adapter: createShardedAdapter(pubClient, subClient)
});

io.listen(3000);

Minimum requirements:

Added in e70b1bd.

Support for node-redis cluster

The redis package now supports Redis cluster.

Added in 77ef42c.

Subscription modes

The subscriptionMode option allows to configure how many Redis Pub/Sub channels are used:

  • "static": 2 channels per namespace

Useful when used with dynamic namespaces.

  • "dynamic": (2 + 1 per public room) channels per namespace

The default value, useful when some rooms have a low number of clients (so only a few Socket.IO servers are notified).

const io = new Server({
  adapter: createShardedAdapter(pubClient, subClient, {
    subscriptionMode: "static"
  })
});

Added in d3388bf.

Credits

Huge thanks to @winchell for helping!

Diff: 8.1.0...8.2.0

Don't miss a new redis-adapter release

NewReleases is sending notifications on new releases.