com.redis.spring.batch.writer.operation.ExpireAt Maven / Gradle / Ivy
The newest version!
package com.redis.spring.batch.writer.operation;
import java.util.function.Function;
import java.util.function.ToLongFunction;
import org.springframework.batch.item.Chunk;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.api.async.RedisKeyAsyncCommands;
public class ExpireAt extends AbstractKeyWriteOperation {
private ToLongFunction epochFunction = t -> 0;
public ExpireAt(Function keyFunction) {
super(keyFunction);
}
public void setEpoch(long epoch) {
this.epochFunction = t -> epoch;
}
public void setEpochFunction(ToLongFunction epochFunction) {
this.epochFunction = epochFunction;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void execute(BaseRedisAsyncCommands commands, T item, K key, Chunk> outputs) {
long millis = epochFunction.applyAsLong(item);
if (millis > 0) {
outputs.add((RedisFuture) ((RedisKeyAsyncCommands) commands).pexpireat(key, millis));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy