首页 > 其他 > 详细

jedis连接sentinel示例程序

时间:2015-12-30 21:53:57      阅读:131      评论:0      收藏:0      [点我收藏+]

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 example
             jedis.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的不再赘述。

 

jedis连接sentinel示例程序

原文:http://www.cnblogs.com/davidwang456/p/5089985.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!