使用redis
本文demo案例扩展自 springboot基础(38):短信验证码缓存案例@CachePut
如何使用Redis- 引入依赖
org.springframework.boot spring-boot-starter-data-redis
- 配置文件
spring:
cache:
type: redis
redis:
cache-null-values: false #是否缓存空值
use-key-prefix: true #是否使用前缀(默认true)
time-to-live: 10s #缓存时间
key-prefix: abc # 指定前缀(如果设置不使用前缀,则指定前缀无效)
redis:
host: 127.0.0.1
port: 6379
- 启动服务器测试



