zoukankan      html  css  js  c++  java
  • Redis集群整合到springboot框架

    整合步骤

      1 配置application.properties

    spring.redis.cluster.nodes=192.168.60.131:8000,192.168.60.131:8001,192.168.60.131:8002
    spring.redis.maxTotal=200
    spring.redis.maxIdle=8
    spring.redis.minIdle=1

      2 编写配置类(完成初始化对象的过程)

     4     @Bean
     5         public JedisCluster getInstance(){
     6             //收集信息
     7             Set<HostAndPort> infoSet=new HashSet<HostAndPort>();
     8             String[] node=nodes.split(",");//192.168.60.131:8000数组
     9             for (String hostAndPort : node) {
    10                 //每次获取192.168.60.131:8000
    11                 String host=hostAndPort.split(":")[0];
    12                 Integer port=Integer.parseInt(hostAndPort.split(":")[1]);
    13                 infoSet.add(new HostAndPort(host, port));}
    14             //配置对象
    15             GenericObjectPoolConfig config=new GenericObjectPoolConfig();
    16             config.setMaxIdle(maxIdle);
    17             config.setMaxTotal(maxTotal);
    18             config.setMinIdle(minIdle);
    19             JedisCluster cluster=new JedisCluster(infoSet,config);
    20             return cluster;}

    3 封装底层api的类(RedisClusterService)

    4 测试

        需求:
        • 存数据,从浏览器传递一些参数id,name
        • 在代码中生成key值,将value存储在cluster集群
        • 通过key值获取集群的value,返回浏览器;

        测试代码端的高可用
      将前面存储的key值所在的节点宕机,再来访问查询的功能观察结果(不能查到,能查到,过一段时间能查到)

      jedisCluster代码客户端高可用

      初始化过程

      

      以set方法出现连接异常为例

  • 相关阅读:
    okHttp源码解析------待续
    AS: Unsupported method: AndroidProject.getPluginGeneration().
    vue项目根据不同环境调用不同请求地址
    文字跑马灯(无缝衔接) CSS+JS完美实现
    data 和 computed 的区别
    ES6解构赋值
    flex布局
    token验证
    vue组件传值
    vue钩子函数
  • 原文地址:https://www.cnblogs.com/nanlinghan/p/9945904.html
Copyright © 2011-2022 走看看