jedis连接sentinel示例程序
生活随笔
收集整理的这篇文章主要介绍了
jedis连接sentinel示例程序
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1.添加依赖pom.xml
<dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>2.8.0</version></dependency>2. java连接
@SuppressWarnings("resource")public static void main(String[] args) {Set<String> sentinels=new HashSet<String>();sentinels.add("192.168.1.80:26379");sentinels.add("192.168.1.81:26379");sentinels.add("192.168.1.82:26379");JedisSentinelPool pool = new JedisSentinelPool("master01", sentinels, new GenericObjectPoolConfig(), 1000);Jedis jedis = pool.getResource();try {/// ... do stuff here ... for examplejedis.set("foo", "bar");String foobar = jedis.get("foo");System.out.println(foobar); /* jedis.zadd("sose", 0, "car"); jedis.zadd("sose", 0, "bike"); Set<String> sose = jedis.zrange("sose", 0, -1);*/} finally {/// ... it's time to release alive/broken Jedis instance...if (null != jedis) {jedis.close();}}/// ... when closing your application: pool.destroy();}3. spring的不再赘述。
转载于:https://www.cnblogs.com/davidwang456/p/5089985.html
总结
以上是生活随笔为你收集整理的jedis连接sentinel示例程序的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: lettuce--Advanced Re
- 下一篇: 连接mongodb,kafka异步处理代