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?
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
They are pretty similar with the following two differences:
@socket.io/redis-adapter
socket.io
server, And you must provide it a publish and subscribe redis client. like the following:io.adapter(createAdapter(pubClient, subClient))
socket.io
commands to/from other servers.@socket.io/redis-emitter
socket.io
server, And you must provide it a publish redis client. like the following:const emitter = new Emitter(pubClient);
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
)