title: Jedis ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context
body: <p>all of a sudden when I try to send a message, I get this error. I don't know why. This has worked fine for a while but then it just stopped working when I tried to send a message. Sometimes it actually sends the message even though the error is thrown but in the listeners, the message is null. I have no idea why this is happening.</p>
  
  <pre><code>redis.clients.jedis.exceptions.JedisDataException: ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context
      at redis.clients.jedis.Protocol.processError(Protocol.java:127) ~[?:?]
      at redis.clients.jedis.Protocol.process(Protocol.java:161) ~[?:?]
      at redis.clients.jedis.Protocol.read(Protocol.java:215) ~[?:?]
      at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340) ~[?:?]
      at redis.clients.jedis.Connection.getIntegerReply(Connection.java:265) ~[?:?]
      at redis.clients.jedis.Jedis.publish(Jedis.java:2690) ~[?:?]
      at com.cursehq.core.communicator.CoreCommunicator.sendMessage(CoreCommunicator.java:117) ~[?:?]
  </code></pre>
  
  <p>Here is the communicator class
      package com.cursehq.core.communicator;</p>
  
  <pre><code>import com.cursehq.core.Core;
  import com.cursehq.core.api.communicator.Communicator;
  import com.cursehq.core.api.communicator.listener.CommunicatorListener;
  import com.cursehq.core.communicator.listeners.*;
  import com.cursehq.core.communicator.message.Message;
  import com.google.gson.Gson;
  import com.google.gson.reflect.TypeToken;
  import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
  import redis.clients.jedis.*;
  
  import java.util.HashSet;
  import java.util.Set;
  
  public class CoreCommunicator implements Communicator {
      private final Set&lt;CommunicatorListener&gt; listeners = new HashSet&lt;&gt;();
      private final Gson gson = new Gson();
      private JedisPool pool;
      private String server;
  
      public boolean load() {
          String host = Core.getCore().getConfig().getString("redis.host");
          int port = Core.getCore().getConfig().getInt("redis.port");
          String password = Core.getCore().getConfig().getString("redis.password");
          server = Core.getCore().getConfig().getString("redis.server");
  
          try {
              pool = new JedisPool(new GenericObjectPoolConfig(), host, port, 20000, password);
              loadServer();
              loadListener();
              loadListeners();
              Core.log("&amp;7Successfully connected to the redis communicator!");
          } catch (Exception e) {
              return false;
          }
          return true;
      }
      public void unload() {
          try (Jedis jedis = pool.getResource()) {
              String json = jedis.get("servers");
              Set&lt;String&gt; set = gson.fromJson(json, new TypeToken&lt;Set&lt;String&gt;&gt;(){}.getType());
              set.remove(server.toLowerCase());
              jedis.set("servers", gson.toJson(set));
              jedis.persist("servers");
          }
      }
  
      private void loadServer() {
          try (Jedis jedis = pool.getResource()) {
              Set&lt;String&gt; set;
              String json = jedis.get("servers");
              if (json == null)
                  set = new HashSet&lt;&gt;();
              else
                  set = gson.fromJson(json, new TypeToken&lt;Set&lt;String&gt;&gt;(){}.getType());
  
              set.add(server.toLowerCase());
              jedis.set("servers", gson.toJson(set));
              jedis.persist("servers");
          }
      }
      private void loadListener() {
          new Thread(() -&gt; {
              try (Jedis jedis = pool.getResource()) {
                  jedis.subscribe(new JedisPubSub() {
                      public void onMessage(String channel, String msg1) {
                          Message message = gson.fromJson(msg1, Message.class);
                          String type = message.getType();
                          String msg = message.getMessage();
                          String from = Core.getCore().getUtils().capitalize(message.getFrom());
  
                          listeners.stream()
                                  .filter(listener -&gt; listener.getType().equalsIgnoreCase(type))
                                  .forEach(listener -&gt; listener.onMessageReceive(msg, from));
                      }
                  }, "all", server.toLowerCase());
              }
          }).start();
      }
      private void loadListeners() {
          new AnnouncementListener();
          new CommandListener();
          new RankUpdateListener();
          new ServerStatusListener();
          new StaffChatListener();
      }
  
      public JedisPool getPool() {
          return pool;
      }
      public String getServerName() {
          return server;
      }
      public String getServers() {
          try (Jedis jedis = pool.getResource()) {
              String json = jedis.get("servers");
              Set&lt;String&gt; servers = gson.fromJson(json, new TypeToken&lt;Set&lt;String&gt;&gt;(){}.getType());
              return String.join(", ", servers);
          }
      }
      public boolean serverExists(String string) {
          try (Jedis jedis = pool.getResource()) {
              Set&lt;String&gt; servers = gson.fromJson(jedis.get("servers"), new TypeToken&lt;Set&lt;String&gt;&gt;(){}.getType());
              return servers.contains(string.toLowerCase());
          }
      }
  
      public void sendMessage(String type, String msg) {
          sendMessage(type, msg, "all");
      }
      public void sendMessage(String type, String msg, String to) {
          try (Jedis jedis = pool.getResource()) {
              Message message = new Message(type, msg);
              String json = gson.toJson(message);
              jedis.publish(to.toLowerCase(), json);
          }
      }
  
      public Set&lt;CommunicatorListener&gt; getListeners() {
          return listeners;
      }
  }
  </code></pre>
  
  <p>If anyone knows what could be causing this error, please share.</p>