springboot集成redis cluster集群

搭建一个springboot项目,整合redis cluster集群配置。

项目pom.xml



	4.0.0
	
		org.springframework.boot
		spring-boot-starter-parent
		2.1.1.RELEASE
		 
	
	com.huateng
	applacation
	0.0.1-SNAPSHOT
	applacation
	Demo project for Spring Boot

	
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter-data-redis
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
		
		
	



application.properties 配置文件

#######Redis配置信息
##############################
#Redis数据库索引
spring.redis.database=0
#Redis服务器地址
spring.redis.cluster.nodes=172.20.10.7:8001,172.20.10.7:8002,172.20.10.7:8003,172.20.10.7:8004,172.20.10.7:8005,172.20.10.7:8006
#Redis服务器连接密码
spring.redis.password=passwd123
#连接超时时间
spring.redis.cluster.timeout=5000
spring.redis.cluster.max-redirects=3
#Redis连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.pool.max-idle=10
# 连接池中的最小空闲连接
spring.redis.pool.min-idle=5

在启动类上添加自动配置注解@EnableAutoConfiguration

package com.huateng.applacation;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAutoConfiguration
public class ApplacationApplication {

	public static void main(String[] args) {
		SpringApplication.run(ApplacationApplication.class, args);
	}

}

测试类

package com.huateng.applacation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @program: applacation
 * @description:
 * @author: daiwenlong
 * @create: 2019-01-18 10:48
 **/
@Component
public class Test implements ApplicationRunner{

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        redisTemplate.opsForValue().set("test", "csdn");
        System.out.println(redisTemplate.opsForValue().get("test"));
    }
}


 

你可能感兴趣的:(redis,springboot)