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

  • 相关阅读:
    ps入门
    ls命名 | Linux统计文件夹内的文件个数
    python打包成可执行文件
    装饰器
    poj 2752 Seek the Name, Seek the Fame
    字符串最大值
    次小生成树
    Selecting Courses
    poj 3461 Oulipo
    poj 2406 Power Strings
  • 原文地址:https://www.cnblogs.com/yjh1995/p/12985918.html
Copyright © 2011-2022 走看看