Skip to content

Best practice for "finding" sockets when using an adapter #5297

Answered by darrachequesne
Thessiah asked this question in Q&A
Discussion options

You must be logged in to vote

Hi!

creating a room for every user when they connect, labeling these rooms with their ID

Yes, that's a good pattern, you can see it for example in our guide with Passport.js: https://socket.io/how-to/use-with-passport#using-the-user-id

I was concerned that bloating the adapter with a large amount of single person rooms

The rooms are stored in the memory of the server the client is currently connected to, basically it's two sets (id to rooms and room to ids).

See also: https://socket.io/docs/v4/rooms/#implementation-details

The adapter based on Redis Streams will only use one single stream, regardless of the number of rooms, so it shouldn't be a concern.

In that case, io.in(userID).fet…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Thessiah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants