socket.iosocket.io-redis

What is the difference between Socket.io Redis adapter and Redis emitter


While I'm reading this article from the Socket.io documentation

I found that the following two packages @socket.io/redis-adapter and @socket.io/redis-emitter are used to emit data to the clients that are on the other servers.

Are these two packages different? And if yes what is the difference? And when to use one instead of the other?


Solution

  • The short answer from Damien — a core committer of Socket.io

    The adapter is a component inside the Socket.IO server, while the emitter can be used in another process/service.

    And there are two diagrams in the documentation explaining the duties of each package


    The long answer

    They are pretty similar with the following two differences:

    @socket.io/redis-adapter

    1. Must be linked with a socket.io server, And you must provide it a publish and subscribe redis client. like the following:
    io.adapter(createAdapter(pubClient, subClient))
    
    1. Responsible to send/receive socket.io commands to/from other servers.

    @socket.io/redis-emitter

    1. Can't be linked with a socket.io server, And you must provide it a publish redis client. like the following:
    const emitter = new Emitter(pubClient);
    
    1. Responsible only to send socket.io commands to the other servers (that has @socket.io/redis-adapter adapter with the same redis database connection and channel key configuration)

    Note: These differences applies to all socket.io adapters and emitters (e.g. @socket.io/mongo-adapter and @socket.io/mongo-emitter)