一、加入依賴
<dependency> <groupId>com.github.spt-oss</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>2.0.7.0</version> </dependency>redis依賴
二、添加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=2000msredis組態檔
三、加載redis.properties組態檔
在@SpringBootApplication注解的類上加上
@PropertySource({ "classpath:redis.properties" })四、獲取操作物件
獲取redis操作物件
@Autowired
private RedisTemplate<String, String> redisTemplate;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/29469.html
標籤:NoSQL
上一篇:mongodb使用_遍歷串列中的元素,作為變數,回圈修改mongodb中的欄位
下一篇:Redis 資料結構
