Data storage

Discussion in 'Spigot Plugin Development' started by 112madgamer, May 7, 2017.

  1. I am not looking for specific help I am just asking about some ways of storing data and best practices to follow. But I would also like to know if this would be a good way to store data.

    Data is stored in SQL -> player logs on (call made to DB) -> data is then cached in Redis until logoff

    Is that a good way to use SQL and Redis together?
  2. Well you'd need to perdiodically save the data over to the DB again. Depending on the PlayerQuitEvent to save their data is almost guaranteed data loss (the server can crash etc). Same goes for the login/join event. Use it, but if owner installs plugin and reloads: players online won't have their data loaded. So you must have a way, for example:

    PlayerD data = new PlayerData(uuid);
    Now, the constructor would make a call to check if the data to this uuid is loaded/exists, and if it doesn't: it creates a new instance. Else it just returns an instance with the already loaded/stored data.

    How is it stored in redis? Hoping you will have an object to represent the player data.

    I personally just use JSON flatfiles, and GSON for serialization and deserialization. It's quite convinient. I then load all players into memory on startup.
    • Agree Agree x 1
  3. Periodically saving your data as @ExpDev said would be the safe way of doing it. You can also load data onEnable foreach player online and save data onDisable, this will fix the issue when a server owner reloads, however not for a server crash, although server crashes are bound to lose some data anyway. As well as the Join/Quit event already mentioned^
  4. Okay cool. For the crashes say it was a prefix plugin I wouldn't need to save it periodically as it would only get updated when they change it right?

    So I then ask what is redis actually used for in spigot I know it is fast but can I get a example of a use case?
  5. I've never used Redis. I think you also have to shade Redis, as it isn't included in the Spigot API.

    At least, this wiki page should contain all you need: .

    Well, depends how you want to use it.
  6. IDK as it was just a idea for it