<dependency> <groupId>com.github.spt-oss</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>2.0.7.0</version> </dependency>
# REDIS (RedisProperties) # Redis數據庫索引(默認爲0) spring.redis.database=0 # Redis服務器地址 spring.redis.host=127.0.0.1 # Redis服務器鏈接端口 spring.redis.port=6379 # Redis服務器鏈接密碼(默認爲空) spring.redis.password=123456 # 鏈接池最大鏈接數(使用負值表示沒有限制) spring.redis.pool.max-active=8 # 鏈接池最大阻塞等待時間(使用負值表示沒有限制) spring.redis.pool.max-wait=-1 # 鏈接池中的最大空閒鏈接 spring.redis.pool.max-idle=8 # 鏈接池中的最小空閒鏈接 spring.redis.pool.min-idle=0 # 鏈接超時時間(毫秒) #加了鏈接池能夠不用設置 spring.redis.timeout=2000ms
在@SpringBootApplication註解的類上加上git
@PropertySource({ "classpath:redis.properties" })
獲取redis操做對象github
@Autowired
private RedisTemplate<String, String> redisTemplate;