C
C#2y ago
.

✅ How to correctly implement a lobby system with Redis?

I am making a web game using SignalR and am looking to scale horizontally. Right now I'm designing a service to create, delete, and connect to a lobby. I want to make it possible for 1 player to be in only 1 lobby at the moment. I chose Redis as the storage for this. How should I describe player and lobby states using Redis features? I had an idea to make two key-value stores, one that will store the id of the lobby to which the player is connected by player id. And in the second repository for the lobby ID, store the json description of the lobby (name, password). But in this case, I have the following problems: how to generate a unique ID for the lobby using redis? And maybe there is a way using some data structures to make a quick search for all the players in the same lobby? (faster than O(n))? Or might it be worth storing the state in a completely different way?
3 Replies
cumslvt13
cumslvt132y ago
data structures to make a quick search for all the players in the same lobby - you can make another key value pair which will track lobby -> players relationship. Key would be lobby id and value is set of user id's how to generate a unique ID for the lobby using redis - ids can be generated on your backend using GUID/snowflake id
Omnissiah
Omnissiah2y ago
i don't even understand why would you need to check for all the players, if you are already managing everything like, if a player already has a relation to a lobby (possibly in a dedicated structure) then he cannot enter another lobby
.
.OP2y ago
Thanks!
Want results from more Discord servers?
Add your server