Esempio n. 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();
 }
Esempio n. 2
0
 private RedisConnection retrieveConnection(SubscribesConnectionEntry entry) {
   if (entry.isFreezed() || !entry.getConnectionsSemaphore().tryAcquire()) {
     return null;
   } else {
     RedisConnection conn = entry.getConnections().poll();
     if (conn != null) {
       return conn;
     }
     try {
       return entry.connect(config);
     } catch (RedisException e) {
       entry.getConnectionsSemaphore().release();
       // TODO connection scoring
       log.warn("Can't connect to {}, trying next connection!", entry.getClient().getAddr());
       return null;
     }
   }
 }