標籤:使用 mapping redis 最小 gre frame sof images 空閑
(1)pom.xml檔案引入jar包,如下:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId></dependency>
(2)application.properties檔案中配置redis串連資訊,如下:
# Redis資料庫索引(預設為0)spring.redis.database=0# Redis伺服器位址spring.redis.host=172.31.19.222# Redis伺服器串連連接埠spring.redis.port=6379# Redis伺服器串連密碼(預設為空白)spring.redis.password=# 串連池最大串連數(使用負值表示沒有限制)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=0
(3)測試redis緩衝
package springboot.web;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.StringRedisTemplate;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HelloController { @Autowired private StringRedisTemplate stringRedisTemplate; @RequestMapping("/redisHandler") public String redisHandler(){ stringRedisTemplate.opsForValue().set("k5", "Springboot redis"); return stringRedisTemplate.opsForValue().get("k5"); }}
(4)啟動項目,調用reidsHandler方法,查詢redis伺服器資訊,如下:
SpringBoot使用Redis資料庫