Ejemplo n.º 1
0
 final Set<UUID> getPlayers() {
   ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
   if (pool != null) {
     try (Jedis rsc = pool.getResource()) {
       List<String> keys = new ArrayList<>();
       for (String i : getServerIds()) {
         keys.add("proxy:" + i + ":usersOnline");
       }
       if (!keys.isEmpty()) {
         Set<String> users = rsc.sunion(keys.toArray(new String[keys.size()]));
         if (users != null && !users.isEmpty()) {
           for (String user : users) {
             try {
               setBuilder = setBuilder.add(UUID.fromString(user));
             } catch (IllegalArgumentException ignored) {
             }
           }
         }
       }
     } catch (JedisConnectionException e) {
       // Redis server has disappeared!
       getLogger()
           .log(
               Level.SEVERE,
               "Unable to get connection from pool - did your Redis server go away?",
               e);
       throw new RuntimeException("Unable to get all players online", e);
     }
   }
   return setBuilder.build();
 }
Ejemplo n.º 2
0
  @Before
  public void setUp() throws Exception {
    Jedis jedis = new Jedis(redis1.host, redis1.port);
    jedis.auth("foobared");
    jedis.flushAll();
    jedis.disconnect();
    jedis = new Jedis(redis2.host, redis2.port);
    jedis.auth("foobared");
    jedis.flushAll();
    jedis.disconnect();

    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
    JedisShardInfo si1 = new JedisShardInfo(redis1.host, redis1.port);
    si1.setPassword("foobared");
    shards.add(si1);
    JedisShardInfo si2 = new JedisShardInfo(redis2.host, redis2.port);
    si2.setPassword("foobared");
    shards.add(si2);
    this.jedis = new ShardedJedis(shards);
  }