springBoot整合redis集群

直接上代码:

1.pom.xml



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

2.application.yaml

spring:
  redis:
    database: 0 
    cluster:
      nodes: 192.168.111.130:8001,192.168.111.130:8002,192.168.111.130:8003
    pool:
      max-active: 300
      max-wait: -1
      max-idle: 20
      min-idle: 10
    timeout: 60000

3.服务启动入口

@SpringBootApplication
@MapperScan(basePackages = {"com.newlan.dao"})  //mybatis扫描
@EnableTransactionManagement //事务
@EnableCaching //开启缓存 redis
public class SpringBootWebApplication {

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

}

4.简单使用

@Component
@Order(value=1)
public class StartupRunner implements CommandLineRunner {

    Log logger = LogFactory.getLog(StartupRunner.class);

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void run(String... strings) throws Exception {
        
        redisTemplate.opsForValue().set("cs","value!!!!!!!!!!!");
        logger.info("###################"+redisTemplate.opsForValue().get("cs"));
        redisTemplate.opsForValue().set("cs","value$$$$$$$$$");
        logger.info("###################"+redisTemplate.opsForValue().get("cs"));

    }
}

 

你可能感兴趣的:(springcloud)