1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| @Configuration @PropertySource("classpath:/properties/redis.properties") public class RedisConfig {
@Value("${redis.nodes}") private String nodes;
@Bean public ShardedJedis shardedJedis(){ List<JedisShardInfo> shards = new ArrayList<>(); String[] nodeArray = nodes.split(","); for (String node : nodeArray){ String host = node.split(":")[0]; int port = Integer.parseInt(node.split(":")[1]); shards.add(new JedisShardInfo(host, port)); } return new ShardedJedis(shards); } }
|