springboot 2.X+redis+springcache 之 数据缓存

本文介绍了如何在SpringBoot 2.x应用中结合Redis和SpringCache实现数据缓存,包括配置pom.xml、application.properties、RedisConfig文件,以及使用注解进行缓存操作。同时,文章提到了在配置过程中可能遇到的问题,如类型转换错误,以及Redis的一些常用操作,如查看key类型、删除key等,并提供了参考资料。
摘要由CSDN通过智能技术生成
Redis简介
Redis支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使用。
Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
Redis支持数据的备份,即master-slave模式的数据备份。 

第一步:
pom.xml文件:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

第二步:
application.properties文件:

spring.redis.database=0
# redis server host
spring.redis.host=127.0.0.1
# redis password
spring.redis.password=
# connection port
spring.redis.port=6379
# time out
spring.redis.timeout=10000
# 配置缓存过期时间
spring.redis.expiretime=1800

# pool settings:
# 连接池中的最大空闲连接
spring.redis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.pool.min-idle=0
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1

# set Key prefix.
# spring.cache.redis.key-prefix=dev
# Entry expiration in milliseconds. By default the entries never expire.
spring.cache.redis.time-to-live=1d
# Whether to use the key prefix when writing to Redis.
spring.cache.redis.use-key-prefix=true

第三步:

编写RedisConfig文件:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值