Download Latest Version 8.3.0 source code.tar.gz (273.0 kB)
Email in envelope

Get an email when there's a new version of Socket.IO Redis Adapter

Home / 8.2.0
Name Modified Size InfoDownloads / Week
Parent folder
8.2.0 source code.tar.gz 2023-05-02 78.9 kB
8.2.0 source code.zip 2023-05-02 86.1 kB
README.md 2023-05-02 2.4 kB
Totals: 3 Items   167.4 kB 0

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:

:::js
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).

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

Added in d3388bf.

Credits

Huge thanks to @winchell for helping!

Diff: https://github.com/socketio/socket.io-redis-adapter/compare/8.1.0...8.2.0

Source: README.md, updated 2023-05-02