Spring Redis - Indexes Are Not Deleted After Master Record Expires

I am saving new entries using the Spring Data Repository. I have a TTL of 10 seconds for each record.

When I save a record with indexes, this is what I get in redis

127.0.0.1:6379> keys * 1) "job:campaignId:aa" 2) "job:a6d6e491-5d75-4fd0-bd8e-71692f6d18be" 3) "job:recipient:dd" 4) "job:a6d6e491-5d75-4fd0-bd8e-71692f6d18be:phantom" 5) "job:listId:cc" 6) "job:accountId:bb" 7) "job" 8) "job:a6d6e491-5d75-4fd0-bd8e-71692f6d18be:idx"

After the expiration date, I still have the data:

127.0.0.1:6379> keys * 1) "job:campaignId:aa" 2) "job:recipient:dd" 3) "job:listId:cc" 4) "job:accountId:bb" 5) "job" 6) "job:a6d6e491-5d75-4fd0-bd8e-71692f6d18be:idx"

Without TTL. Why don't they delete themselves? How can i do this?

thank

+4
source share
2 answers

Spring Data Redis repositories use several Redis functions to store domain objects in Redis.

(job:a6d6e491-5d75-4fd0-bd8e-71692f6d18be). , Redis . Spring Data Redis (job:campaignId:aa, job:recipient:dd), . . , , , .

So Spring Data Redis phantom hash (job:a6d6e491-5d75-4fd0-bd8e-71692f6d18be:phantom) TTL.

Spring Data Redis ( @EnableRedisRepositories(enableKeyspaceEvents = EnableKeyspaceEvents.ON_STARTUP) . , Spring Data Redis phantom ( ).

, , :

  • , , , , . , Redis, , , .
  • @EnableRedisRepositories ( keypace-events), Keyspace , Spring Data Redis .
+7

/ , .

, , .

redis> SET mykey "Hello"
"OK"
redis> EXPIRE mykey 10
(integer) 1

: https://redis.io/commands/expire

Spring

@Component
public class RedisUtil {
    @Autowired
    private RedisTemplate<String, String> template;

    @Resource(name = "redisTemplate")
    ValueOperations<String, String> ops;

    public boolean addValue(String key, String value) {

        if (template.hasKey(Constants.REDIS_KEY_PREFIX + key)) {
            // key is already there
            return false;
        } else {
            ops.set(Constants.REDIS_KEY_PREFIX + key, value);
            template.expireAt(Constants.REDIS_KEY_PREFIX + key, 10);
        }
        return true;
    }
}
0

Source: https://habr.com/ru/post/1666991/


All Articles