Redis PubSub problem

Discussion in 'Spigot Help' started by MrGG4ming, Jan 17, 2020.

  1. Hi, I'm trying to work with Redis and I'm trying to communicate from server to server using Redis. Well before anyone comes to recommend the "Bungee Plugin Messaging Channel" I have no interest, I want to make a communication that goes far beyond the limits of the bungee reaching other machines if necessary. I understood more or less how Redis works, but I'm having a problem with establishing a connection with a messaging channel.
    Code (Text):
    package com.mcm.core;

    import redis.clients.jedis.JedisPubSub;

    public class RedisChannel extends JedisPubSub {

        public static void subscribe() {
            new Thread("thread_redis_subscriber"){
                @Override
                public void run(){
                    JedisPubSub jedisPubSub = new JedisPubSub() {
                        @Override
                        public void onMessage(String channel, String message) {
                            if (channel.equalsIgnoreCase("chat_global")) {
                                System.out.println(message);
                            }
                        }
                    };
                    Redis.localhost.subscribe(jedisPubSub, "chat_global");
                }
            };
        }

        public static void publish(String channel, String message) {
            Redis.localhost.publish(channel, message);
        }
    }
     
    Code (Text):
    public class Main extends JavaPlugin {

        public static Main instance;
        public static Plugin plugin;

        @Override
        public void onEnable() {
            Main.instance = this;
            Main.plugin = this;
            RedisChannel.subscribe();
        }
    }
    I realized that it must run async, otherwise the server crash, but this way if I send it does not return my "System.out.print", I wanted to understand where I went wrong, and what I am not understanding, I am grateful to anyone who can help me!