Skip to content

RedisAPI for communication between the MineCrossing website and game server

Notifications You must be signed in to change notification settings

MineCrossing/RedisAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RedisAPI

RedisAPI for communication between the MineCrossing website and game server

Maven Repository

To use RedisAPI run the following commands:

git clone https://github.com/MineCrossing/RedisAPI.git
cd RedisAPI
mvn install

Then add this into your dependencies section in your pom.xml

<dependency>
    <groupId>xyz.minecrossing</groupId>
    <artifactId>RedisAPI</artifactId>
    <version>1.0.0</version>
</dependency>

Example Usage

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"

Publishing and Subscribing

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");
Debugging

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.

About

RedisAPI for communication between the MineCrossing website and game server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages