zoukankan      html  css  js  c++  java
  • 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 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的不再赘述。

  • 相关阅读:
    Zabbix 3.2.1 安装 Graphtree3.0.4 或 Graphtree3.2.x
    jquery-1
    AngularJS (1)
    css-2 (Text Font)
    css
    Java经验
    js经验
    mysql经验
    MySQL 函数
    jquery 效果
  • 原文地址:https://www.cnblogs.com/davidwang456/p/5089985.html
Copyright © 2011-2022 走看看