com.redis.spring.batch.writer.operation.Restore Maven / Gradle / Ivy
The newest version!
package com.redis.spring.batch.writer.operation;
import org.springframework.batch.item.Chunk;
import com.redis.spring.batch.common.KeyValue;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.RestoreArgs;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.api.async.RedisKeyAsyncCommands;
public class Restore extends AbstractKeyWriteOperation> {
public Restore() {
super(KeyValue::getKey);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void execute(BaseRedisAsyncCommands commands, KeyValue item, K key,
Chunk> outputs) {
RedisKeyAsyncCommands keyCommands = (RedisKeyAsyncCommands) commands;
if (item.getValue() == null || item.getTtl() == KeyValue.TTL_KEY_DOES_NOT_EXIST) {
outputs.add((RedisFuture) keyCommands.del(item.getKey()));
} else {
RestoreArgs args = new RestoreArgs().replace(true);
if (item.getTtl() > 0) {
args.absttl().ttl(item.getTtl());
}
outputs.add((RedisFuture) keyCommands.restore(item.getKey(), (byte[]) item.getValue(), args));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy