@Test public void getPlayersProxies() { repository.setPlayerProxy("proxy-1", "a"); repository.setPlayerProxy("proxy-2", "b"); repository.setPlayerProxy("proxy-3", "c"); Map<String, String> playersProxies = repository.getPlayersProxies(Arrays.asList("a", "b", "c")); assertEquals(new HashSet<>(Arrays.asList("proxy-1", "proxy-2", "proxy-3")), new HashSet<>(playersProxies.values())); }
@Override public Map<String, String> getPlayersProxies(Collection<String> playerNames) { return redisTransactions.runTransaction(jedis -> { Map<String, Response<String>> pipelineResponses = new HashMap<>(); Pipeline pipeline = jedis.pipelined(); playerNames.forEach( name -> pipelineResponses.put(name, pipeline.hget(playerHashTable(name), PROXY)) ); pipeline.sync(); return pipelineResponses .entrySet() .stream() .filter(e -> e.getValue().get() != null) .collect(Collectors.toMap( Map.Entry::getKey, e -> e.getValue().get() )); }); }
RedisPlayerRepository implements PlayerRepository { @Override public Map<String, String> getPlayersProxies(Collection<String> playerNames) { return redisTransactions.runTransaction(jedis -> { Map<String, Response<String>> pipelineResponses = new HashMap<>(); Pipeline pipeline = jedis.pipelined(); playerNames.forEach( name -> pipelineResponses.put(name, pipeline.hget(playerHashTable(name), PROXY)) ); pipeline.sync(); return pipelineResponses .entrySet() .stream() .filter(e -> e.getValue().get() != null) .collect(Collectors.toMap( Map.Entry::getKey, e -> e.getValue().get() )); }); } }
RedisPlayerRepository implements PlayerRepository { @Override public Map<String, String> getPlayersProxies(Collection<String> playerNames) { return redisTransactions.runTransaction(jedis -> { Map<String, Response<String>> pipelineResponses = new HashMap<>(); Pipeline pipeline = jedis.pipelined(); playerNames.forEach( name -> pipelineResponses.put(name, pipeline.hget(playerHashTable(name), PROXY)) ); pipeline.sync(); return pipelineResponses .entrySet() .stream() .filter(e -> e.getValue().get() != null) .collect(Collectors.toMap( Map.Entry::getKey, e -> e.getValue().get() )); }); }  }
RedisPlayerRepository implements PlayerRepository { @Override public Map<String, String> getPlayersProxies(Collection<String> playerNames) { return redisTransactions.runTransaction(jedis -> { Map<String, Response<String>> pipelineResponses = new HashMap<>(); Pipeline pipeline = jedis.pipelined(); playerNames.forEach( name -> pipelineResponses.put(name, pipeline.hget(playerHashTable(name), PROXY)) ); pipeline.sync(); return pipelineResponses .entrySet() .stream() .filter(e -> e.getValue().get() != null) .collect(Collectors.toMap( Map.Entry::getKey, e -> e.getValue().get() )); }); }  @Override void setPlayerServer(String server, String playerName); @Override Map<String, String> getPlayersProxies(Collection<String> playerNames); @Override void setPlayerProxy(String player, String playerName); @Override Optional<String> getPlayerServer(String playerName); @Override Optional<String> getPlayerProxy(String playerName); @Override void deletePlayerData(String player); }
RedisPlayerRepository implements PlayerRepository { @Override public Map<String, String> getPlayersProxies(Collection<String> playerNames) { return redisTransactions.runTransaction(jedis -> { Map<String, Response<String>> pipelineResponses = new HashMap<>(); Pipeline pipeline = jedis.pipelined(); playerNames.forEach( name -> pipelineResponses.put(name, pipeline.hget(playerHashTable(name), PROXY)) ); pipeline.sync(); return pipelineResponses .entrySet() .stream() .filter(e -> e.getValue().get() != null) .collect(Collectors.toMap( Map.Entry::getKey, e -> e.getValue().get() )); }); }  @Override void setPlayerServer(String server, String playerName); @Override Map<String, String> getPlayersProxies(Collection<String> playerNames); @Override void setPlayerProxy(String player, String playerName); @Override Optional<String> getPlayerServer(String playerName); @Override Optional<String> getPlayerProxy(String playerName); @Override void deletePlayerData(String player);  }