Skip to content

Redis组件

redis组件,是在spring-boot-starter-data-redis的基础上,定义了Redis的值序列化器 FastJson2JsonRedisSerializer及工具类 RedisHelper,maven坐标如下:

xml
<dependency>
    <groupId>cn.zjtele.pubinfo.boot</groupId>
    <artifactId>pubinfo-boot-starter-redis</artifactId>
</dependency>

Redis序列化器配置

组件基于fastjson2,通过实现RedisSerializer,定义了redis的值序列化器FastJson2JsonRedisSerializer,实现redis获取值时自动序列化为java对象。 由于fastjson2关闭了autoType白名单,我们需要自己配置autoType白名单,具体配置示例如下:

yaml
pubinfo:
  fastjson2:
    auto-filters:
      - cn.zjtele.pubinfo.sys.auth.spi.domain.ValidCode
      - cn.zjtele.pubinfo.sys.auth.core.domain.entity.PubLoginLock
      - cn.zjtele.pubinfo.sys.dict.core.domain.entity.PubDictItem

RedisHelper

组件提供了redis操作的工具类RedisHelper,提供了reids的常用操作方法。

缓存前缀

  • 底座默认使用系统名(spring.application.name)作为redis缓存前缀
  • 可以设置默认缓存前缀,特别是微服务环境下,各个服务(认证服务、系统管理服务、网关服务及业务服务)的缓存前缀要一致
yaml
pubinfo:
  # 下面是注释掉的缓存配置示例
  cache:
    config-map:
      default:
        redis:
          key-prefix: xxxx