Springboot整合redis步驟

1、加入依賴


		<dependency>
			<groupId>com.github.spt-oss</groupId>
			<artifactId>spring-boot-starter-data-redis</artifactId>
			<version>2.0.7.0</version>
		</dependency>
redis依賴

2、添加redis.properties配置文件

# 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
redis配置文件

3、加載redis.properties配置文件

在@SpringBootApplication註解的類上加上git

@PropertySource({ "classpath:redis.properties" })

4、獲取操做對象

獲取redis操做對象github

@Autowired
private RedisTemplate<String, String> redisTemplate;
相關文章
相關標籤/搜索