refactoring

pull/6384/head
Nikita Koksharov 2 months ago
parent 5dd631caad
commit 4d73d8d97d

@ -17,13 +17,13 @@ package org.redisson.eviction;
import io.netty.util.Timeout; import io.netty.util.Timeout;
import io.netty.util.TimerTask; import io.netty.util.TimerTask;
import org.redisson.api.RFuture;
import org.redisson.command.CommandAsyncExecutor; import org.redisson.command.CommandAsyncExecutor;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Deque; import java.util.Deque;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -63,7 +63,7 @@ abstract class EvictionTask implements TimerTask {
timeout.cancel(); timeout.cancel();
} }
abstract RFuture<Integer> execute(); abstract CompletionStage<Integer> execute();
abstract String getName(); abstract String getName();
@ -73,7 +73,7 @@ abstract class EvictionTask implements TimerTask {
return; return;
} }
RFuture<Integer> future = execute(); CompletionStage<Integer> future = execute();
future.whenComplete((size, e) -> { future.whenComplete((size, e) -> {
if (e != null) { if (e != null) {
log.error("Unable to evict elements for '{}'", getName(), e); log.error("Unable to evict elements for '{}'", getName(), e);

@ -15,13 +15,13 @@
*/ */
package org.redisson.eviction; package org.redisson.eviction;
import java.util.Arrays;
import org.redisson.api.RFuture;
import org.redisson.client.codec.LongCodec; import org.redisson.client.codec.LongCodec;
import org.redisson.client.protocol.RedisCommands; import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor; import org.redisson.command.CommandAsyncExecutor;
import java.util.Arrays;
import java.util.concurrent.CompletionStage;
/** /**
* *
* @author Nikita Koksharov * @author Nikita Koksharov
@ -46,7 +46,7 @@ public class JCacheEvictionTask extends EvictionTask {
} }
@Override @Override
RFuture<Integer> execute() { CompletionStage<Integer> execute() {
return executor.evalWriteAsync(name, LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER, return executor.evalWriteAsync(name, LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER,
"local expiredKeys = redis.call('zrangebyscore', KEYS[2], 0, ARGV[1], 'limit', 0, ARGV[2]); " "local expiredKeys = redis.call('zrangebyscore', KEYS[2], 0, ARGV[1], 'limit', 0, ARGV[2]); "
+ "for i, k in ipairs(expiredKeys) do " + "for i, k in ipairs(expiredKeys) do "

@ -67,7 +67,7 @@ public class MapCacheEvictionTask extends EvictionTask {
} }
@Override @Override
RFuture<Integer> execute() { CompletionStage<Integer> execute() {
int latchExpireTime = Math.min(delay, 30); int latchExpireTime = Math.min(delay, 30);
RFuture<Integer> expiredFuture = executor.evalWriteNoRetryAsync(name, LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER, RFuture<Integer> expiredFuture = executor.evalWriteNoRetryAsync(name, LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER,
"if redis.call('setnx', KEYS[6], ARGV[4]) == 0 then " "if redis.call('setnx', KEYS[6], ARGV[4]) == 0 then "

@ -15,13 +15,13 @@
*/ */
package org.redisson.eviction; package org.redisson.eviction;
import java.util.Arrays;
import org.redisson.api.RFuture;
import org.redisson.client.codec.LongCodec; import org.redisson.client.codec.LongCodec;
import org.redisson.client.protocol.RedisCommands; import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor; import org.redisson.command.CommandAsyncExecutor;
import java.util.Arrays;
import java.util.concurrent.CompletionStage;
/** /**
* *
* @author Nikita Koksharov * @author Nikita Koksharov
@ -43,7 +43,7 @@ public class MultimapEvictionTask extends EvictionTask {
return name; return name;
} }
RFuture<Integer> execute() { CompletionStage<Integer> execute() {
return executor.evalWriteAsync(name, LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER, return executor.evalWriteAsync(name, LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER,
"local expiredKeys = redis.call('zrangebyscore', KEYS[2], 0, ARGV[1], 'limit', 0, ARGV[2]); " "local expiredKeys = redis.call('zrangebyscore', KEYS[2], 0, ARGV[1], 'limit', 0, ARGV[2]); "
+ "if #expiredKeys > 0 then " + "if #expiredKeys > 0 then "

@ -15,11 +15,12 @@
*/ */
package org.redisson.eviction; package org.redisson.eviction;
import org.redisson.api.RFuture;
import org.redisson.client.codec.LongCodec; import org.redisson.client.codec.LongCodec;
import org.redisson.client.protocol.RedisCommands; import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor; import org.redisson.command.CommandAsyncExecutor;
import java.util.concurrent.CompletionStage;
/** /**
* *
* @author Nikita Koksharov * @author Nikita Koksharov
@ -42,7 +43,7 @@ public class ScoredSetEvictionTask extends EvictionTask {
} }
@Override @Override
RFuture<Integer> execute() { CompletionStage<Integer> execute() {
return executor.writeAsync(name, LongCodec.INSTANCE, RedisCommands.ZREMRANGEBYSCORE, name, 0, System.currentTimeMillis() - shiftInMilliseconds); return executor.writeAsync(name, LongCodec.INSTANCE, RedisCommands.ZREMRANGEBYSCORE, name, 0, System.currentTimeMillis() - shiftInMilliseconds);
} }

@ -15,12 +15,12 @@
*/ */
package org.redisson.eviction; package org.redisson.eviction;
import org.redisson.api.RFuture;
import org.redisson.client.codec.LongCodec; import org.redisson.client.codec.LongCodec;
import org.redisson.client.protocol.RedisCommands; import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor; import org.redisson.command.CommandAsyncExecutor;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.CompletionStage;
/** /**
* *
@ -39,7 +39,7 @@ public class TimeSeriesEvictionTask extends EvictionTask {
} }
@Override @Override
RFuture<Integer> execute() { CompletionStage<Integer> execute() {
return executor.evalWriteAsync(name, LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER, return executor.evalWriteAsync(name, LongCodec.INSTANCE, RedisCommands.EVAL_INTEGER,
"local expiredKeys = redis.call('zrangebyscore', KEYS[2], 0, ARGV[1], 'limit', 0, ARGV[2]); " "local expiredKeys = redis.call('zrangebyscore', KEYS[2], 0, ARGV[1], 'limit', 0, ARGV[2]); "
+ "if #expiredKeys > 0 then " + "if #expiredKeys > 0 then "

Loading…
Cancel
Save