云数据库 GAUSSDB NOSQL-通过Jedis连接实例:使用JedisPool访问(推荐)

时间:2023-11-10 12:13:25

使用JedisPool访问(推荐)

样例代码

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class JedisPoolTests {

  private static void testPool() {
    String pwd = "a";
     
    JedisPool pool = new JedisPool(new GenericObjectPoolConfig(), "172.xx.xx.xx", 8635,
        2000, pwd);
    Jedis jedis = pool.getResource();
    try {
      System.out.println(jedis.hgetAll("676296"));
      System.out.println(jedis.set("key1", "value1"));
    } finally {
      jedis.close();
    }
    pool.destroy();
  }

  public static void main(String[] args) {
    testPool();
  }
}
support.huaweicloud.com/productdesc-nosql/nosql_09_0103.html