Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: socketio/socket.io-redis-adapter
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2e0ca4e002423849cdd6e01526ff2f239568042b
Choose a base ref
...
head repository: socketio/socket.io-redis-adapter
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ed83ba9559098375a2149273c8870e24f4f7827a
Choose a head ref

Commits on Jan 16, 2017

  1. Copy the full SHA
    01028d0 View commit details

Commits on Feb 7, 2017

  1. Copy the full SHA
    38b8a2b View commit details
  2. Copy the full SHA
    1dc1a9b View commit details

Commits on Feb 15, 2017

  1. [fix] Fix remoteJoin/remoteLeave methods (#201)

    The callback was triggered before the socket has actually joined/left
    the room.
    darrachequesne authored Feb 15, 2017
    Copy the full SHA
    7ae896a View commit details
  2. Copy the full SHA
    2354068 View commit details

Commits on May 10, 2017

  1. Copy the full SHA
    bceab01 View commit details
  2. Copy the full SHA
    a33499d View commit details
  3. [chore] Release 4.0.1

    darrachequesne committed May 10, 2017
    Copy the full SHA
    d3d000b View commit details
  4. [perf] Use pattern matching at the namespace level (#217)

    This follows #46. Each node will now listen to only three channels:
    
    - `socket.io#<namespace>#*`: used when broadcasting
    - `socket.io-request#<namespace>#`: used for requesting information (ex: get every room in the cluster)
    - `socket.io-response#<namespace>#`: used for responding to requests
    
    We keep the benefits of #46 since:
    
    - messages from other namespaces are ignored
    - when emitting to a single room, the message is sent to
      `socket.io#<namespace>#<my-room>`, so listeners can check whether they
      have the room before unpacking the message (which is CPU consuming).
    
    But there is no need to subscribe / unsubscribe every time a socket
    joins or leaves a room (which is also CPU consuming when there are
    thousands of subscriptions).
    darrachequesne authored May 10, 2017
    Copy the full SHA
    05f926e View commit details
  5. Copy the full SHA
    f42e26d View commit details
  6. [chore] Release 5.0.0

    darrachequesne committed May 10, 2017
    Copy the full SHA
    5f475fb View commit details

Commits on May 13, 2017

  1. [fix] Fix broken protocol in 5.0.0 (#221)

    The message is now published to `socket.io#<namespace>#<my-room>#`
    channel, instead of `socket.io#<namespace>#<my-room>`.
    darrachequesne authored May 13, 2017
    Copy the full SHA
    8dd84c7 View commit details
  2. [chore] Release 5.0.1

    darrachequesne committed May 13, 2017
    Copy the full SHA
    c743d61 View commit details

Commits on Jun 4, 2017

  1. [fix] Use the requestid from response when deleting requests (#225)

    Request does not have a requestid property so requests were not being
    cleaned up and .requests object was leaking memory.
    beaucollins authored and darrachequesne committed Jun 4, 2017
    Copy the full SHA
    4f08b1a View commit details
  2. Copy the full SHA
    b3ad4ad View commit details
  3. [chore] Bump dependencies (#227)

    - bump debug to version 2.6.8
    - bump redis to version 2.7.1
    - bump ioredis to version 3.1.1
    - bump mocha to version 3.4.2
    darrachequesne authored Jun 4, 2017
    Copy the full SHA
    dfe1401 View commit details
  4. [chore] Release 5.1.0

    darrachequesne committed Jun 4, 2017
    Copy the full SHA
    f978d24 View commit details

Commits on Jun 14, 2017

  1. Copy the full SHA
    d6586a1 View commit details

Commits on Aug 23, 2017

  1. Copy the full SHA
    b97c96d View commit details
  2. [feat] Increase default requestsTimeout to 5000 ms (#243)

    That should solve most 'timeout reached while waiting for response' errors.
    darrachequesne authored Aug 23, 2017
    Copy the full SHA
    37e28df View commit details
  3. Copy the full SHA
    ba2b2e6 View commit details
  4. [docs] Add note about compatibility (#238)

    Add note about compatibility, as described in https://github.com/socketio/socket.io-redis/releases/tag/5.0.0
    luislobo authored and darrachequesne committed Aug 23, 2017
    Copy the full SHA
    142f742 View commit details

Commits on Aug 24, 2017

  1. [chore] Release 5.2.0

    darrachequesne committed Aug 24, 2017
    Copy the full SHA
    f27d2b8 View commit details

Commits on Feb 22, 2018

  1. [docs] Update README.md about requestsTimeout (#258)

    Following #243
    DingGGu authored and darrachequesne committed Feb 22, 2018
    Copy the full SHA
    5fe5dad View commit details

Commits on Feb 27, 2018

  1. Copy the full SHA
    91fb8ed View commit details
  2. Copy the full SHA
    353870b View commit details

Commits on May 4, 2018

  1. Copy the full SHA
    e9cbe30 View commit details
  2. [docs] Fix Cluster example in the README

    The previous example would lead to "Connection in subscriber mode, only subscriber commands may
    be used" errors.
    
    Fixes #274
    darrachequesne committed May 4, 2018
    Copy the full SHA
    8fe4e03 View commit details

Commits on Sep 26, 2018

  1. Copy the full SHA
    6d787fb View commit details
  2. Copy the full SHA
    a1cebc8 View commit details

Commits on Jun 4, 2020

  1. chore: bump debug to version 4.1.0 (#306)

    Co-authored-by: Dimitar Nestorov <dimitarnestorov@users.noreply.github.com>
    DimitarNestorov and DimitarNestorov authored Jun 4, 2020
    Copy the full SHA
    d6242d9 View commit details
  2. Copy the full SHA
    f257303 View commit details
  3. Copy the full SHA
    2500964 View commit details
  4. chore: add docker-compose.yml file

    For local tests.
    darrachequesne committed Jun 4, 2020
    Copy the full SHA
    597a8d1 View commit details
  5. feat: add support for Redis Cluster

    The 'numsub' command only returns the number of subscribers on the
    current node, so we have to ask every node of the cluster.
    
    Fixes #267
    Fixes #210
    laurentP22 authored Jun 4, 2020
    Copy the full SHA
    7a19075 View commit details
  6. chore(release): 5.3.0

    darrachequesne committed Jun 4, 2020
    Copy the full SHA
    ed83ba9 View commit details
Showing with 1,004 additions and 324 deletions.
  1. +5 −6 .travis.yml
  2. +30 −0 CHANGELOG.md
  3. +0 −105 History.md
  4. +91 −27 README.md
  5. +6 −0 docker-compose.yml
  6. +97 −163 index.js
  7. +732 −0 package-lock.json
  8. +9 −10 package.json
  9. +34 −13 test/index.js
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
language: node_js
sudo: false
node_js:
- "0.10"
- "0.12"
- "4"
- "6"
- "node"
- "8"
- "10"
- "12"
- "13"
notifications:
irc: "irc.freenode.org#socket.io"
services:
- redis-server
- redis
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# [5.3.0](https://github.com/socketio/socket.io-redis/compare/5.2.0...5.3.0) (2020-06-04)


### Features

* add support for Redis Cluster ([7a19075](https://github.com/socketio/socket.io-redis/commit/7a190755c01732d1335199732e7b0eb5a1fb1f9e))



# [5.2.0](https://github.com/socketio/socket.io-redis/compare/5.1.0...5.2.0) (2017-08-24)


### Features

* increase default requestsTimeout to 5000 ms ([37e28df](https://github.com/socketio/socket.io-redis/commit/37e28df54b0b8c71b4f8ea1766e56dc63fb26ba2))



# [5.1.0](https://github.com/socketio/socket.io-redis/compare/5.0.1...5.1.0) (2017-06-04)

### Bug Fixes

* use the requestid from response when deleting requests ([4f08b1a](https://github.com/socketio/socket.io-redis/commit/4f08b1ae7b3b9ee549349f1b95f5e3f3ff69d651))


### Features

* add support for ArrayBuffer ([b3ad4ad](https://github.com/socketio/socket.io-redis/commit/b3ad4ad28b225f1999d5dd709f2ea6d5674085f6))


105 changes: 0 additions & 105 deletions History.md

This file was deleted.

118 changes: 91 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,15 +6,29 @@
## How to use

```js
var io = require('socket.io')(3000);
var redis = require('socket.io-redis');
io.adapter(redis({ host: 'localhost', port: 6379 }));
const io = require('socket.io')(3000);
const redisAdapter = require('socket.io-redis');
io.adapter(redisAdapter({ host: 'localhost', port: 6379 }));
```

By running socket.io with the `socket.io-redis` adapter you can run
multiple socket.io instances in different processes or servers that can
all broadcast and emit events to and from each other.

So any of the following commands:

```js
io.emit('hello', 'to all clients');
io.to('room42').emit('hello', "to all clients in 'room42' room");

io.on('connection', (socket) => {
socket.broadcast.emit('hello', 'to all clients except sender');
socket.to('room42').emit('hello', "to all clients in 'room42' room except sender");
});
```

will properly be broadcast to the clients through the Redis Pub/Sub mechanism.

If you need to emit events to socket.io instances from a non-socket.io
process, you should use [socket.io-emitter](https://github.com/socketio/socket.io-emitter).

@@ -32,11 +46,9 @@ The following options are allowed:
- `key`: the name of the key to pub/sub events on as prefix (`socket.io`)
- `host`: host to connect to redis on (`localhost`)
- `port`: port to connect to redis on (`6379`)
- `subEvent`: optional, the redis client event name to subscribe to (`messageBuffer`)
- `pubClient`: optional, the redis client to publish events on
- `subClient`: optional, the redis client to subscribe to events on
- `requestsTimeout`: optional, after this timeout the adapter will stop waiting from responses to request (`1000ms`)
- `withChannelMultiplexing`: optional, whether channel multiplexing is enabled (a new subscription will be trigggered for each room) (`true`)
- `requestsTimeout`: optional, after this timeout the adapter will stop waiting from responses to request (`5000ms`)

If you decide to supply `pubClient` and `subClient`, make sure you use
[node_redis](https://github.com/mranney/node_redis) as a client or one
@@ -58,21 +70,27 @@ that a regular `Adapter` does not
Returns the list of client IDs connected to `rooms` across all nodes. See [Namespace#clients(fn:Function)](https://github.com/socketio/socket.io#namespaceclientsfnfunction)

```js
io.adapter.clients(function (err, clients) {
io.of('/').adapter.clients((err, clients) => {
console.log(clients); // an array containing all connected socket ids
});

io.adapter.clients(['room1', 'room2'], function (err, clients) {
io.of('/').adapter.clients(['room1', 'room2'], (err, clients) => {
console.log(clients); // an array containing socket ids in 'room1' and/or 'room2'
});

// you can also use

io.in('room3').clients((err, clients) => {
console.log(clients); // an array containing socket ids in 'room3'
});
```

### RedisAdapter#clientRooms(id:String, fn:Function)

Returns the list of rooms the client with the given ID has joined (even on another node).

```js
io.adapter.clientRooms('<my-id>', function (err, rooms) {
io.of('/').adapter.clientRooms('<my-id>', (err, rooms) => {
if (err) { /* unknown id */ }
console.log(rooms); // an array containing every room a given id has joined.
});
@@ -83,7 +101,7 @@ io.adapter.clientRooms('<my-id>', function (err, rooms) {
Returns the list of all rooms.

```js
io.adapter.allRooms(function (err, rooms) {
io.of('/').adapter.allRooms((err, rooms) => {
console.log(rooms); // an array containing all rooms (accross every node)
});
```
@@ -93,7 +111,7 @@ io.adapter.allRooms(function (err, rooms) {
Makes the socket with the given id join the room. The callback will be called once the socket has joined the room, or with an `err` argument if the socket was not found.

```js
io.adapter.remoteJoin('<my-id>', 'room1', function (err) {
io.of('/').adapter.remoteJoin('<my-id>', 'room1', (err) => {
if (err) { /* unknown id */ }
// success
});
@@ -104,7 +122,7 @@ io.adapter.remoteJoin('<my-id>', 'room1', function (err) {
Makes the socket with the given id leave the room. The callback will be called once the socket has left the room, or with an `err` argument if the socket was not found.

```js
io.adapter.remoteLeave('<my-id>', 'room1', function (err) {
io.of('/').adapter.remoteLeave('<my-id>', 'room1', (err) => {
if (err) { /* unknown id */ }
// success
});
@@ -115,7 +133,7 @@ io.adapter.remoteLeave('<my-id>', 'room1', function (err) {
Makes the socket with the given id to get disconnected. If `close` is set to true, it also closes the underlying socket. The callback will be called once the socket was disconnected, or with an `err` argument if the socket was not found.

```js
io.adapter.remoteDisconnect('<my-id>', true, function (err) {
io.of('/').adapter.remoteDisconnect('<my-id>', true, (err) => {
if (err) { /* unknown id */ }
// success
});
@@ -127,12 +145,12 @@ Sends a request to every nodes, that will respond through the `customHook` metho

```js
// on every node
io.adapter.customHook = function (data) {
return 'hello ' + data;
io.of('/').adapter.customHook = (data, cb) => {
cb('hello ' + data);
}

// then
io.adapter.customRequest('john', function(err, replies){
io.of('/').adapter.customRequest('john', function(err, replies){
console.log(replies); // an array ['hello john', ...] with one element per node
});
```
@@ -143,8 +161,7 @@ Access the `pubClient` and `subClient` properties of the
Redis Adapter instance to subscribe to its `error` event:

```js
var redis = require('socket.io-redis');
var adapter = redis('localhost:6379');
const adapter = require('socket.io-redis')('localhost:6379');
adapter.pubClient.on('error', function(){});
adapter.subClient.on('error', function(){});
```
@@ -153,9 +170,9 @@ The errors emitted from `pubClient` and `subClient` will
also be forwarded to the adapter instance:

```js
var io = require('socket.io')(3000);
var redis = require('socket.io-redis');
io.adapter(redis({ host: 'localhost', port: 6379 }));
const io = require('socket.io')(3000);
const redisAdapter = require('socket.io-redis');
io.adapter(redisAdapter({ host: 'localhost', port: 6379 }));
io.of('/').adapter.on('error', function(){});
```

@@ -166,11 +183,58 @@ that has a password, use pub/sub options instead of passing
a connection string.

```js
var redis = require('redis').createClient;
var adapter = require('socket.io-redis');
var pub = redis(port, host, { auth_pass: "pwd" });
var sub = redis(port, host, { auth_pass: "pwd" });
io.adapter(adapter({ pubClient: pub, subClient: sub }));
const redis = require('redis');
const redisAdapter = require('socket.io-redis');
const pub = redis.createClient(port, host, { auth_pass: "pwd" });
const sub = redis.createClient(port, host, { auth_pass: "pwd" });
io.adapter(redisAdapter({ pubClient: pub, subClient: sub }));
```

## With [ioredis](https://github.com/luin/ioredis) client

### Cluster example

```js
const io = require('socket.io')(3000);
const redisAdapter = require('socket.io-redis');
const Redis = require('ioredis');

const startupNodes = [
{
port: 6380,
host: '127.0.0.1'
},
{
port: 6381,
host: '127.0.0.1'
}
];

io.adapter(redisAdapter({
pubClient: new Redis.Cluster(startupNodes),
subClient: new Redis.Cluster(startupNodes)
}));
```

### Sentinel Example

```js
const io = require('socket.io')(3000);
const redisAdapter = require('socket.io-redis');
const Redis = require('ioredis');

const options = {
sentinels: [
{ host: 'somehost1', port: 26379 },
{ host: 'somehost2', port: 26379 }
],
name: 'master01'
};

io.adapter(redisAdapter({
pubClient: new Redis(options),
subClient: new Redis(options)
}));
```

## Protocol
@@ -194,7 +258,7 @@ A number of other libraries adopt this protocol including:

- [socket.io-emitter](https://github.com/socketio/socket.io-emitter)
- [socket.io-python-emitter](https://github.com/GameXG/socket.io-python-emitter)

- [socket.io-emitter-go](https://github.com/stackcats/socket.io-emitter-go)

## License

6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '2.0'
services:
redis:
image: redis:5
ports:
- "6379:6379"
Loading