标签:port 成功 res info ssh client color xid date
ShardedJedis用法
package com.zhi.demo; import java.util.Arrays; import java.util.List; import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisShardInfo; import redis.clients.jedis.ShardedJedis; import redis.clients.jedis.ShardedJedisPool; /** * 多个redis服务器获取连接 * * @date 2019年03月07日19:33:05 * */ public class SharedRedis { private static ShardedJedisPool shardedJedisPool; static { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(5); config.setTestOnBorrow(false); JedisShardInfo info1 = new JedisShardInfo("192.168.153.137", 6379); JedisShardInfo info2 = new JedisShardInfo("192.168.153.137", 6379); List<JedisShardInfo> infoList = Arrays.asList(info1, info2); shardedJedisPool = new ShardedJedisPool(config, infoList); } public static void main(String[] args) { try (ShardedJedis jedis = shardedJedisPool.getResource()) { System.out.println("获取reidis连接成功"); if ("OK".equals(jedis.set("reids", "reids"))) { System.out.println("向redis设置值成功"); } else { System.out.println("向redis设置值失败"); } }
// 关闭资源池,否则线程会一直等待 shardedJedisPool.close(); System.out.println("关闭redis资源池"); } }
标签:port 成功 res info ssh client color xid date
原文地址:https://www.cnblogs.com/zhi-leaf/p/10502704.html