
com.redis.spring.batch.writer.ExpireAt Maven / Gradle / Ivy
package com.redis.spring.batch.writer;
import java.util.List;
import java.util.function.Function;
import java.util.function.ToLongFunction;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.api.async.RedisKeyAsyncCommands;
public class ExpireAt extends AbstractKeyOperation {
private ToLongFunction epochFunction = t -> 0;
public ExpireAt(Function keyFunction) {
super(keyFunction);
}
public ExpireAt epoch(long epoch) {
return epoch(t -> epoch);
}
public ExpireAt epoch(ToLongFunction function) {
this.epochFunction = function;
return this;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void execute(BaseRedisAsyncCommands commands, T item, K key, List> outputs) {
long ttl = epochFunction.applyAsLong(item);
if (ttl > 0) {
outputs.add((RedisFuture) ((RedisKeyAsyncCommands) commands).pexpireat(key, ttl));
}
}
public static ExpireAt of(Function key, ToLongFunction epoch) {
return new ExpireAt(key).epoch(epoch);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy