1. 概述
本文介绍如何通过springboot集成redis并简单介绍其原理。
2. Demo和原理
2.1. application.properties
application.properties配置参数如下
spring.redis.database=0
spring.redis.host=192.168.188.7
spring.redis.password=
spring.redis.port=6379
spring.redis.pool.max-idle=8
spring.redis.pool.min-idle=0
spring.redis.pool.max-active=8
spring.redis.pool.max-wait=-1
备注: 如果你要使用集群redis,则可以配置以下参数spring.redis.sentinel.* 或 spring.redis.cluster.*
2.2. RedisProperties
以上参数会被自动封装到RedisProperties中: 此类被@ConfigurationProperties注解,表示从外部文件(如application.properties)注入属性值
@ConfigurationProperties(prefix = "spring.redis")
public class RedisProperties {
/**
* Database index use