socket.io-redis-adapter
socket.io-redis-adapter copied to clipboard
Retrieving number of connected sockets using `fetchSockets` without getting all socket information
Hi,
We will need to add a function with the functionality mentioned in the title
(Retrieving number of connected sockets using fetchSockets
without getting all socket information)
Currently, in high loaded systems, we have too much traffic in redis since each handshake of a socket contains a lot of information (all the headers, the session info, etc)
Thanks.
I will try to push a PR soon.
Hi! Yes, as you have noted the fetchSockets()
method transfers a lot of data.
You should use the serverSideEmit()
method instead:
io.serverSideEmit("hello", "world");
// And on the receiving side:
io.on("hello", (arg1) => {
console.log(arg1); // prints "world"
});
Reference: https://socket.io/docs/v4/server-instance/#serversideemit
Yeah. I have used that for now.
@darrachequesne What do you think about adding the "count" as a separate function? You don't think it would be usable?
I have also an example of a patch with a new function.
What do you think about adding the "count" as a separate function?
I'm not sure that's a good idea, because in most cases I think one wants to count the number of users, not the number of sockets (since a single user can have multiple connections). What do you think?
I second this. I do not care if socket count is not always 1 to 1 with user count. I need a way to count sockets without pulling all data over the wire.
@darrachequesne - Sometimes I actually more interested in the sockets as opposed to the users as @cody-evaluate mentioned.
An example (my case) for that is for horizontal scaling purposes