All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.redis.spring.batch.writer.operation.Expire Maven / Gradle / Ivy

There is a newer version: 4.0.7
Show newest version
package com.redis.spring.batch.writer.operation;

import java.time.Duration;
import java.util.List;
import java.util.function.Function;

import com.redis.spring.batch.util.BatchUtils;

import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.api.async.RedisKeyAsyncCommands;

public class Expire extends AbstractOperation {

    private Function ttl = t -> null;

    public void setTtl(Duration duration) {
        setTtl(t -> duration);
    }

    public void setTtl(Function function) {
        this.ttl = function;
    }

    @SuppressWarnings("unchecked")
    @Override
    public void execute(BaseRedisAsyncCommands commands, T item, List> futures) {
        Duration duration = ttl(item);
        if (BatchUtils.isPositive(duration)) {
            futures.add(((RedisKeyAsyncCommands) commands).pexpire(key(item), duration));
        }
    }

    private Duration ttl(T item) {
        return ttl.apply(item);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy