refactoring

pull/6120/head
Nikita Koksharov 7 months ago
parent c931831a63
commit 3f23018c83

@ -15,10 +15,6 @@
*/
package org.redisson;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.redisson.api.RFuture;
import org.redisson.api.RObject;
import org.redisson.client.codec.LongCodec;
@ -26,6 +22,10 @@ import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandAsyncExecutor;
import org.redisson.eviction.EvictionScheduler;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
*
* @author Nikita Koksharov
@ -35,7 +35,7 @@ import org.redisson.eviction.EvictionScheduler;
class RedissonMultimapCache<K> {
private final CommandAsyncExecutor commandExecutor;
private final RObject object;
private final RedissonObject object;
private final String timeoutSetName;
private final String prefix;
private final EvictionScheduler evictionScheduler;
@ -43,7 +43,7 @@ class RedissonMultimapCache<K> {
RedissonMultimapCache(CommandAsyncExecutor commandExecutor, EvictionScheduler evictionScheduler,
RObject object, String timeoutSetName, String prefix) {
this.commandExecutor = commandExecutor;
this.object = object;
this.object = (RedissonObject) object;
this.timeoutSetName = timeoutSetName;
this.prefix = prefix;
this.evictionScheduler = evictionScheduler;
@ -55,7 +55,7 @@ class RedissonMultimapCache<K> {
public RFuture<Boolean> expireKeyAsync(K key, long timeToLive, TimeUnit timeUnit) {
long ttlTimeout = System.currentTimeMillis() + timeUnit.toMillis(timeToLive);
return commandExecutor.evalWriteAsync(((RedissonObject) object).getRawName(), object.getCodec(), RedisCommands.EVAL_BOOLEAN,
return commandExecutor.evalWriteAsync(object.getRawName(), object.getCodec(), RedisCommands.EVAL_BOOLEAN,
"if redis.call('hexists', KEYS[1], ARGV[2]) == 1 then "
+ "if tonumber(ARGV[1]) > 0 then "
+ "redis.call('zadd', KEYS[2], ARGV[1], ARGV[2]); " +
@ -66,17 +66,17 @@ class RedissonMultimapCache<K> {
+ "else "
+ "return 0; "
+ "end",
Arrays.<Object>asList(((RedissonObject) object).getRawName(), timeoutSetName),
ttlTimeout, ((RedissonObject) object).encodeMapKey(key));
Arrays.asList(object.getRawName(), timeoutSetName),
ttlTimeout, object.encodeMapKey(key));
}
public RFuture<Long> sizeInMemoryAsync() {
List<Object> keys = Arrays.<Object>asList(((RedissonObject) object).getRawName(), timeoutSetName);
return ((RedissonObject) object).sizeInMemoryAsync(keys);
List<Object> keys = Arrays.asList(object.getRawName(), timeoutSetName);
return object.sizeInMemoryAsync(keys);
}
public RFuture<Boolean> deleteAsync() {
return commandExecutor.evalWriteAsync(((RedissonObject) object).getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN_AMOUNT,
return commandExecutor.evalWriteAsync(object.getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN_AMOUNT,
"local entries = redis.call('hgetall', KEYS[1]); " +
"local keys = {KEYS[1], KEYS[2]}; " +
"for i, v in ipairs(entries) do " +
@ -91,12 +91,12 @@ class RedissonMultimapCache<K> {
+ "n = n + redis.call('del', unpack(keys, i, math.min(i+4999, table.getn(keys)))) "
+ "end; "
+ "return n;",
Arrays.asList(((RedissonObject) object).getRawName(), timeoutSetName),
Arrays.asList(object.getRawName(), timeoutSetName),
prefix);
}
public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit, String param) {
return commandExecutor.evalWriteAsync(((RedissonObject) object).getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
return commandExecutor.evalWriteAsync(object.getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
"redis.call('zadd', KEYS[2], 92233720368547758, 'redisson__expiretag'); " +
"local entries = redis.call('hgetall', KEYS[1]); " +
"for i, v in ipairs(entries) do " +
@ -115,12 +115,12 @@ class RedissonMultimapCache<K> {
+ "end; " +
"redis.call('pexpire', KEYS[2], ARGV[1]); " +
"return redis.call('pexpire', KEYS[1], ARGV[1]); ",
Arrays.asList(((RedissonObject) object).getRawName(), timeoutSetName),
Arrays.asList(object.getRawName(), timeoutSetName),
timeUnit.toMillis(timeToLive), prefix, param);
}
public RFuture<Boolean> expireAtAsync(long timestamp, String param) {
return commandExecutor.evalWriteAsync(((RedissonObject) object).getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
return commandExecutor.evalWriteAsync(object.getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
"redis.call('zadd', KEYS[2], 92233720368547758, 'redisson__expiretag');" +
"local entries = redis.call('hgetall', KEYS[1]); " +
"for i, v in ipairs(entries) do " +
@ -139,12 +139,12 @@ class RedissonMultimapCache<K> {
+ "end; " +
"redis.call('pexpireat', KEYS[2], ARGV[1]); " +
"return redis.call('pexpireat', KEYS[1], ARGV[1]); ",
Arrays.<Object>asList(((RedissonObject) object).getRawName(), timeoutSetName),
Arrays.asList(object.getRawName(), timeoutSetName),
timestamp, prefix, param);
}
public RFuture<Boolean> clearExpireAsync() {
return commandExecutor.evalWriteAsync(((RedissonObject) object).getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
return commandExecutor.evalWriteAsync(object.getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
"redis.call('zrem', KEYS[2], 'redisson__expiretag'); " +
"local entries = redis.call('hgetall', KEYS[1]); " +
"for i, v in ipairs(entries) do " +
@ -155,15 +155,15 @@ class RedissonMultimapCache<K> {
"end; " +
"redis.call('persist', KEYS[2]); " +
"return redis.call('persist', KEYS[1]); ",
Arrays.<Object>asList(((RedissonObject) object).getRawName(), timeoutSetName),
Arrays.asList(object.getRawName(), timeoutSetName),
prefix);
}
public void destroy() {
if (evictionScheduler != null) {
evictionScheduler.remove(((RedissonObject) object).getRawName());
evictionScheduler.remove(object.getRawName());
}
((RedissonObject) object).removeListeners();
object.removeListeners();
}
}

Loading…
Cancel
Save