Get all user sessions

First I want to say thanks for the new version!

I occasionally have to get all the user session, the session is stored in redis, but the key session not to store the information about user name, and get session and look for it for a long time, so I keep the sessions separate, I wonder, there is a possibility I’m not aware of? because when you use server side events there is a function NotifyUserName() which sends a message to all sessions.

Thanks.

Sessions are only stored against a session Id, it doesn’t maintain an index by username you’d need to either maintain your own index by handling a Session or Auth Event otherwise there’s an example at the bottom of the session docs that shows how you can retrieve all sessions.

Server Events is an entirely different implementation, each time a subscriber connects it registers multiple indexes, one of them being Username, but this only lets you notify users by username that’s connected to SSE, i.e. not all authenticated users.

Thank you Demis, I have seen an example of how to code sessions but many of them are receiving and filtering may take 1 second and this is for me not acceptable, so I separately indexed the user’s session, as SSE.

If I change the format of the session key is something will have a negative impact?

I wouldn’t be messing with internals like the session key format unless you have a good reason to, anyone relying on the predictable key format is not going to see the changes.

Well Demis, I’ll do that, thank you.