Пример #1
0
 public void returnConnection(RedisConnection connection) {
   SubscribesConnectionEntry entry = clients.get(connection.getRedisClient());
   if (entry.isFreezed()) {
     connection.closeAsync();
   } else {
     entry.getConnections().add(connection);
   }
   entry.getConnectionsSemaphore().release();
 }
Пример #2
0
 @Override
 public Map<String, String> info() {
   RedisConnection c = connect();
   try {
     return c.sync(RedisCommands.CLUSTER_INFO);
   } catch (Exception e) {
     return null;
   } finally {
     c.closeAsync();
   }
 }
Пример #3
0
 @Override
 public boolean ping() {
   RedisConnection c = null;
   try {
     c = connect();
     return "PONG".equals(c.sync(RedisCommands.PING));
   } catch (Exception e) {
     return false;
   } finally {
     if (c != null) {
       c.closeAsync();
     }
   }
 }
Пример #4
0
  public synchronized Collection<RedisPubSubConnection> freeze(String host, int port) {
    InetSocketAddress addr = new InetSocketAddress(host, port);
    for (SubscribesConnectionEntry connectionEntry : clients.values()) {
      if (connectionEntry.isFreezed() || !connectionEntry.getClient().getAddr().equals(addr)) {
        continue;
      }

      log.debug("{} freezed", addr);
      connectionEntry.setFreezed(true);

      // close all connections
      while (true) {
        RedisConnection connection = connectionEntry.getConnections().poll();
        if (connection == null) {
          break;
        }
        connection.closeAsync();
      }

      // close all pub/sub connections
      while (true) {
        RedisPubSubConnection connection = connectionEntry.pollFreeSubscribeConnection();
        if (connection == null) {
          break;
        }
        connection.closeAsync();
      }

      boolean allFreezed = true;
      for (SubscribesConnectionEntry entry : clients.values()) {
        if (!entry.isFreezed()) {
          allFreezed = false;
          break;
        }
      }
      if (allFreezed) {
        clientsEmpty.close();
      }

      List<RedisPubSubConnection> list =
          new ArrayList<RedisPubSubConnection>(connectionEntry.getAllSubscribeConnections());
      connectionEntry.getAllSubscribeConnections().clear();
      return list;
    }

    return Collections.emptyList();
  }