zoukankan      html  css  js  c++  java
  • 一个练手的小项目(二)——Redis集群

    RedisConfig.java:

    package com.tsvv.config;
    
    import java.util.HashSet;
    import java.util.Set;
    
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.PropertySource;
    
    import redis.clients.jedis.HostAndPort;
    import redis.clients.jedis.JedisCluster;
    
    //标识配置类
    @Configuration
    @PropertySource("classpath:/properties/redis.properties")
    public class RedisConfig {
    
        @Value("${redis.clusterNodes}")
        private String nodes;
    
        @Bean
        public JedisCluster jedisCluster() {
            Set<HostAndPort> nodeSet=new HashSet<>();
            String[] arrayNodes=nodes.split(",");
            for (String node : arrayNodes) {
                String host=node.split(":")[0];
                int port=Integer.parseInt(node.split(":")[1]);
                nodeSet.add(new HostAndPort(host, port));
            }
            return new JedisCluster(nodeSet);
        }
        
    }

    redis.properties:

    #最小空闲数
    redis.minIdle=100
    #最大空闲数
    redis.maxIdle=300
    #最大连接数
    redis.maxTotal=1000
    #定义redis节点信息
    redis.clusterNodes=192.168.6.129:7000,192.168.6.129:7001,192.168.6.129:7002,192.168.6.129:7003,192.168.6.129:7004,192.168.6.129:7005
  • 相关阅读:
    String分割成int[]和List<Integer>
    linux查询正在运行的jar包并kill进程
    linux自动清理n天(1个月)前日志文件
    zookeeper命令行操作
    sql开窗函数
    hdfs shell操作
    centos7安装mysql8
    hadoop集群安装
    hdfs基本介绍
    IDEA下运行MAVEN项目,报"程序包******不存在"
  • 原文地址:https://www.cnblogs.com/tsvv-plus/p/11911198.html
Copyright © 2011-2022 走看看