Spring doesn't set expiration time for records on Redis cache

Viewed 577

I have the project where I send Objects to Redis cache, but Spring doesn't set expiration time for records. I tried in many ways:

  1. By setting @TimeToLive annotation to field.

  2. By adding @RedisHash(timeToLive = 60).

  3. By adding spring.cache.redis.time-to-live: 6000 to properties.

    @Data
     @EqualsAndHashCode(callSuper = false)
     @Generated
     @RedisHash(timeToLive = 60)
     public class GetPackages extends GetPackagesType implements Serializable {
    
         private static final long serialVersionUID = -3086056567387275373L;
         private int BID;
         @TimeToLive
         Long ttl = 120L;
     }
    

But redis-cli says there is no TTL set for mykey.

redis 127.0.0.1:6378> TTL mykey  
(integer) -1

I use:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.3.RELEASE</version>
</parent>

I tried with 2.3.11.RELEASE, but it's the same.

I use dependencies:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
</dependency>
0 Answers
Related