0

Here is an example of what I want my data structure to look like:

[games]:
   [game_1]:
       players: 10
       maxPlayers: 24
       state: "PLAYING"
       currentMap: "Example Map"
   [game_2]:
       players: 0
       maxPlayers: 24
       state: "LOBBY"
       currentMap: "None"

I am using the Java implementation of Redis (Jedis) in order to cache data from registered game servers. A proxy server connects all the registered game servers together, however, the proxy cannot relay data such as this. Therefore, I have gone with the Redis approach and integrated it into the core plugin which is shared across all of the game servers. The lobby server will be able to access the data from Redis to display live game statistics to the players. How would I go about structuring this? I'm fairly new to Redis and hours of searching did not help. Please do explain this in simple terms. I would like to be able to make method calls to get the data for a specific game and iterate through all cached games in the Redis database. (e.g. games: {"game_1", "game_2"})

1 Answer 1

2

One way to go about this would be:

  1. Store your games in Hashes - a Hash per game. The Hash's key name should be your game's identifier and the fields->values in it should correspond to your game's properties. In Redis lingo that should be done with:

    HMSET game_1 players 10 maxPlayers 24 state PLAYING currentMap "Example Map"

  2. Updates to a game can simply call HSET game_1 players 11 to touch specific properties.

  3. You can get read a specific game's property, properties or all properties with HGET, HMGET and HGETALL respectively.

  4. Getting all the games can be done in one of two ways:

    a. Use SCAN to retrieve the key names in your database, and call the APIs in step 3 on each. Pro: no additional maintenance, con: could be slower.

    b. Maintain a Set of that consists of your game identifiers (key names) - to fetch all games, get the contents of that Set and for each of its members use the APIs in step 3. Pro: better performance for fetching all games, con: requires maintaining another data structure (the Set).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.