核心代码

spring:
  cache:
    type: REDIS
    redis:
      time-to-live: 28800000
      custom-ttl: { "xxx" : "1000000", "yyy": "6000000"}

 

@Data
@Component
@Configuration
@ConfigurationProperties(prefix = "spring.cache.redis")
public class HiteamRedisConfig {

    //如果为空默认为12个小时
    @Value("${spring.cache.redis.time-to-live:43200000}")
    private Long redisKeyTtl;

    private HashMap<String, Long> customTtl;

 

注意,这里使用@Value无法注入,spring版本:2.2.6

问题:如果custom-ttl中存在特殊字符的话无法实现,因此改用下面的方式

      custom-ttl:
        "[tst:auth:spaceRoles]" : 1000000
        "[tst:auth:spaceUser]": 6000000

 

posted on 2023-05-11 19:37  张释文  阅读(353)  评论(0编辑  收藏  举报