socket.io-redis-adapter

Adapter to enable broadcasting of events to multiple separate socket.io server nodes.

MIT License

Downloads
883.3K
Stars
2.7K
Committers
57

Bot releases are hidden (Show)

socket.io-redis-adapter - 8.3.0 Latest Release

Published by darrachequesne 7 months ago

Bug Fixes

  • sharded: allow to target a specific socket ID in dynamic mode (#525) (cca38dc)
  • sharded: fix count in fetchSockets() method (#523) (bd32763)
  • sharded: fix SSUBSCRIBE memory leak with ioredis (#529) (2113e8d)

Features

  • sharded: add an option for dynamic private channels (#526) (50220f4)

Links

socket.io-redis-adapter - 8.2.1

Published by darrachequesne over 1 year ago

Bug Fixes

  • sharded: ensure compatibility with ioredis (42c8ab6)
  • sharded: properly unsubscribe when closing (2da8d9e)

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

socket.io-redis-adapter - 8.2.0

Published by darrachequesne over 1 year 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: https://github.com/socketio/socket.io-redis-adapter/compare/8.1.0...8.2.0

socket.io-redis-adapter - 8.1.0

Published by darrachequesne over 1 year ago

The socket.io-adapter package was added to the list of peerDependencies, in order to fix sync issues with the version imported by the socket.io package (see f07ff7b).

Features

Automatic removal of empty child namespaces

The close() method was implemented, in order to be used with the new cleanupEmptyChildNamespaces option.

Reference: https://github.com/socketio/socket.io/releases/tag/4.6.0

Added in fe89f7e.

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

socket.io-redis-adapter - 8.0.1

Published by darrachequesne almost 2 years ago

This release pins the socket.io-adapter package to version ~2.4.0 instead of ^2.4.0.

Diff: https://github.com/socketio/socket.io-redis-adapter/compare/8.0.0...8.0.1

socket.io-redis-adapter - 8.0.0

Published by darrachequesne almost 2 years ago

Dependencies

Features

  • add option to allow usage of custom parser (#471) (73f6320)

Example with msgpackr:

import { unpack, pack } from "msgpackr";

io.adapter(createAdapter(pubClient, subClient, {
  parser: {
    encode(val) {
      return pack(val);
    },
    decode(val) {
      return unpack(val);
    }
  }
}));
  • remove deprecated methods (fb760d9)

BREAKING CHANGES

  • the remoteJoin(), remoteLeave(), remoteDisconnect() and sockets() methods are removed in favor of the official alternatives

Related: https://github.com/socketio/socket.io/commit/b25495c069031674da08e19aed68922c7c7a0e28

  • the format of Date objects is modified in a non backward-compatible way, as notepack.io now implements the MessagePack Timestamp extension type.

Reference: https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type

Previous versions of the adapter will not be able to parse the Date objects sent by newer versions.

Diff: https://github.com/socketio/socket.io-redis-adapter/compare/7.2.0...8.0.0

socket.io-redis-adapter - 7.2.0

Published by darrachequesne over 2 years ago

Bug Fixes

Features

  • broadcast and expect multiple acks (e4c40cc)

This feature was added in [email protected]:

io.timeout(1000).emit("some-event", (err, responses) => {
  // ...
});

Thanks to this change, it will now work with multiple Socket.IO servers.

Diff: https://github.com/socketio/socket.io-redis-adapter/compare/7.1.0...7.2.0

socket.io-redis-adapter - 7.1.0

Published by darrachequesne almost 3 years ago

Features

  • add support for redis v4 (aa681b3)
  • do not emit "error" events anymore (8e5c84f)

Error handling can now be done on the redis clients directly.

Before:

io.of("/").adapter.on("error", () => {
  // ...
});

After:

pubClient.on("error", () => {
  // something went wrong
});

subClient.on("error", () => {
  // something went wrong
});
  • send response to the requesting node only (f66de11)

A more performant way to do request-response is available behind an option, publishOnSpecificResponseChannel:

const io = require('socket.io')(3000);
const { createClient } = require('redis');
const redisAdapter = require('@socket.io/redis-adapter');

const pubClient = createClient({ host: 'localhost', port: 6379 });
const subClient = pubClient.duplicate();
io.adapter(redisAdapter(pubClient, subClient, {
  publishOnSpecificResponseChannel: true
}));

To upgrade an existing deployment, you will need to upgrade all nodes to the latest version with publishOnSpecificResponseChannel = false, and then toggle the option on each node.

Please check the commit for more information.

Links

socket.io-redis-adapter - 7.0.1

Published by darrachequesne almost 3 years ago

Bug Fixes

  • allow numeric rooms (214b5d1)
  • ignore sessionStore in the fetchSockets method (c5dce43)

Links

socket.io-redis-adapter - 7.0.0

Published by darrachequesne over 3 years ago

⚠️ IMPORTANT ⚠️

The package was renamed to @socket.io/redis-adapter, in order to match the name of the Redis emitter (@socket.io/redis-emitter).

Features

  • implement the serverSideEmit functionality (3a0f29f)
  • remove direct redis dependency (c68a47c)
  • rename the package to @socket.io/redis-adapter (3cac178)

BREAKING CHANGES

  • the library will no longer create Redis clients on behalf of the user.

Before:

io.adapter(redisAdapter({ host: "localhost", port: 6379 }));

After:

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

io.adapter(redisAdapter(pubClient, subClient));

Links

socket.io-redis-adapter - 6.1.0

Published by darrachequesne over 3 years ago

Features

  • implement utility methods from Socket.IO v4 (468c3c8)

Performance Improvements

  • remove one round-trip for the requester (6c8d770)

Links

socket.io-redis-adapter - 6.0.1

Published by darrachequesne almost 4 years ago

Bug Fixes

  • typings: properly expose the createAdapter method (0d2d69c)
  • fix broadcasting (#361) (3334d99)

Links

socket.io-redis-adapter - 6.0.0

Published by darrachequesne almost 4 years ago

⚠️ This release is only compatible with Socket.IO v3. For Socket.IO v2, please use previous versions.

See also: https://github.com/socketio/socket.io-redis#compatibility-table

Features

  • add support for Socket.IO v3 (d9bcb19)

BREAKING CHANGES:

  • all the requests (for inter-node communication) now return a Promise instead of accepting a callback

Before:

io.of('/').adapter.allRooms((err, rooms) => {
  console.log(rooms); // an array containing all rooms (across every node)
});

After:

const rooms = await io.of('/').adapter.allRooms();
console.log(rooms); // a Set containing all rooms (across every node)
  • RedisAdapter.clients() is renamed to RedisAdapter.sockets()

See https://github.com/socketio/socket.io-adapter/commit/130f28a43c5aca924aa2c1a318422d21ba03cdac

  • RedisAdapter.clientRooms() is removed

It has been replaced by the fetchSockets() method in Socket.IO v4:

const sockets = await io.in(theSocketId).fetchSockets();
if (sockets.length) {
  console.log(sockets[0].rooms);
}
  • RedisAdapter.customHook() and RedisAdapter.customRequest() are removed

Those methods will be replaced by a more intuitive API in a future iteration.

  • support for Node.js 8 is dropped

See https://github.com/nodejs/Release

Links

socket.io-redis-adapter - 5.4.0

Published by darrachequesne about 4 years ago

Features

  • update node-redis version to 3.x (fa4d474)

Links

socket.io-redis-adapter - 5.3.0

Published by darrachequesne over 4 years ago

Features

  • add support for Redis Cluster (7a19075)

Links

socket.io-redis-adapter -

Published by darrachequesne about 7 years ago

Features

  • increase default requestsTimeout to 5000 ms (#243)

Links

socket.io-redis-adapter -

Published by darrachequesne over 7 years ago

Features

  • add support for ArrayBuffer (#226)

Bug fixes

  • use the requestid from response when deleting requests (#225)

Links

socket.io-redis-adapter -

Published by darrachequesne over 7 years ago

Bug fixes

  • fix broken protocol in 5.0.0 (#221)

Milestone: 5.0.1
Diff: 5.0.0...5.0.1

socket.io-redis-adapter -

Published by darrachequesne over 7 years ago

Performance improvements

  • use notepack instead of msgpack-lite (#218)
  • use pattern matching at the namespace level (#217)

⚠️ Breaking changes ⚠️

This is the first version compatible with socket.io v2. Please use previous versions (4.x) for socket.io v1.x. If not, you may encounter Cannot read property 'encode' of undefined errors.

Milestone: 5.0.0
Diff: 4.0.1...5.0.0

socket.io-redis-adapter -

Published by darrachequesne over 7 years ago

Bug fixes

  • fix duplicate identifier declaration (#213)

Milestone: 4.0.1
Diff: 4.0.0...4.0.1