RedisAPI for communication between the MineCrossing website and game server
To use RedisAPI run the following commands:
git clone https://github.com/MineCrossing/RedisAPI.git
cd RedisAPI
mvn installThen add this into your dependencies section in your pom.xml
<dependency>
<groupId>xyz.minecrossing</groupId>
<artifactId>RedisAPI</artifactId>
<version>1.0.0</version>
</dependency>Note: Redis calls should always be done asynchronously to avoid blocking the main thread.
See CoreUtilities#getTaskManager
Jedis jedis = RedisConnector.getInstance().getConnection();
// Key, Value
jedis.get("test"); // Returns value, "hello"
jedis.set("key", "value"); // Sets a key, value storage
// Using Lists
jedis.lpush("queue#players", "Player1", "Player2"); // Add 2 players to list
jedis.lpush("queue#players", "Player3"); // Add 1 player to list
String player = jedis.rpop("queue#players"); // Returns "Player1"When listening (subscribing) to a specific channel you need to use a RedisChannelListener and register it.
RedisConnector.getInstance().listenForChannel("channelName", new RedisChannelListener());Example class for a RedisChannelListener
public class ChannelListener implements RedisChannelListener {
@Override
public void messageReceived(String message) {
System.out.println("Received message: " + message);
}
}When publishing it is a very simple process of sending out a message (or serialised data)
RedisConnector.getInstance().getConnection().publish("debug", "test");RedisAPI has some light debugging available, it will always listen to the debug channel and you can publish messages there for testing like the example above.