zoukankan      html  css  js  c++  java
  • Jerdi使用和常用方法命令

    三种连接Redis的方法

    方法一:单机连接池连接

    JedisPoolConfig jedisPoolConfig=new JedisPoolConfig();
    JedisPool jedisPool=new JedisPool(jedisPoolConfig,"host","port",2000,"password");
    Jedis jedis=jedisPool.getResource();
    //关闭连接,将资源归还连接池
    jedis.close();
    jedisPool.close();

    方法二:ShardedJedisPool 集群连接

    //创建 poolConfig
    JedisPoolConfig poolConfig=new JedisPoolConfig();
    //设置 JedisShardInfo信息,host post password
    JedisShardInfo jedisShardInfo1=new JedisShardInfo("host1","port1");
    jedisShardInfo1.setPassword("password1");
    JedisShardInfo jedisShardInfo2=new JedisShardInfo("host2","port2");
    jedisShardInfo2.setPassword("password2");
    JedisShardInfo jedisShardInfo3=new JedisShardInfo("host3","port3");
    jedisShardInfo3.setPassword("password3");
    
    List<JedisShardInfo> list= Arrays.asList(jedisShardInfo1,jedisShardInfo2,jedisShardInfo3);
    //创建连接池 ShardedJedisPool
    ShardedJedisPool jedisPool=new ShardedJedisPool(poolConfig,list);
    //获取 jedis
    ShardedJedis jedis=jedisPool.getResource();
    //关闭连接,将资源归还连接池
    jedis.close();
    jedisPool.close();

    方法三:JedisCluster 集群连接

    //节点添加
    Set<HostAndPort> nodes=new HashSet<HostAndPort>();
    nodes.add(new HostAndPort("host1","port1"));
    nodes.add(new HostAndPort("host2","port2"));
    nodes.add(new HostAndPort("host3","port3"));
    //创建 JedisCluster
    JedisCluster jedis=new JedisCluster(nodes,2000,2000,5,"password",new JedisPoolConfig());
    jedis.close();

    JedisCluster与ShardedJedisPool的区别

    https://blog.csdn.net/qq_31102103/article/details/89372143

  • 相关阅读:
    windows ntstatus.h 头文件
    Android Q 后台启动 Activity
    windows 删除文件夹所有文件夹及文件代码
    Android 加壳App Demo
    Android App 签名保护demo
    RXAndroidBle 记录网址
    c++ windows 获取系统时间
    js 代码保存
    day33 ansible
    day31 综合实时同步服务
  • 原文地址:https://www.cnblogs.com/yjh1995/p/12985918.html
Copyright © 2011-2022 走看看