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异步处理代