Jedis Sentinel 连接池配置详解
Jedis Sentinel 连接池配置详解
JedisSentinelConnection 是 Jedis 提供的一个连接 Sentinel 集群的连接池,可以通过以下配置进行配置:
1. 连接池配置
可以通过以下方式配置连接池:
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(10);
poolConfig.setMaxIdle(5);
poolConfig.setMinIdle(1);
poolConfig.setTestOnBorrow(true);
2. 连接 Sentinel 配置
可以通过以下方式配置连接 Sentinel 集群:
Set<String> sentinels = new HashSet<String>();
sentinels.add('127.0.0.1:26379');
JedisSentinelPool jedisSentinelPool = new JedisSentinelPool('mymaster', sentinels, poolConfig);
其中,'mymaster' 是 Sentinel 集群的 master 节点的名称。
3. 连接密码配置
如果 Sentinel 集群需要密码进行连接,可以通过以下方式进行配置:
JedisSentinelPool jedisSentinelPool = new JedisSentinelPool('mymaster', sentinels, poolConfig, 'password');
其中,'password' 是 Sentinel 集群的密码。
4. 连接超时配置
可以通过以下方式配置连接超时时间:
JedisSentinelPool jedisSentinelPool = new JedisSentinelPool('mymaster', sentinels, poolConfig, 1000, 'password');
其中,1000 表示连接超时时间,单位为毫秒。
原文地址: https://www.cveoy.top/t/topic/nXIb 著作权归作者所有。请勿转载和采集!