|
|
@ -17,7 +17,6 @@ package org.redisson;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collection;
|
|
|
@ -41,8 +40,6 @@ import org.redisson.core.RSetCache;
|
|
|
|
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
|
import io.netty.handler.codec.base64.Base64;
|
|
|
|
|
|
|
|
import io.netty.util.CharsetUtil;
|
|
|
|
|
|
|
|
import io.netty.util.concurrent.Future;
|
|
|
|
import io.netty.util.concurrent.Future;
|
|
|
|
import net.openhft.hashing.LongHashFunction;
|
|
|
|
import net.openhft.hashing.LongHashFunction;
|
|
|
|
|
|
|
|
|
|
|
@ -320,13 +317,20 @@ public class RedissonSetCache<V> extends RedissonExpirable implements RSetCache<
|
|
|
|
|
|
|
|
|
|
|
|
long timeoutDate = System.currentTimeMillis() + unit.toMillis(ttl);
|
|
|
|
long timeoutDate = System.currentTimeMillis() + unit.toMillis(ttl);
|
|
|
|
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN,
|
|
|
|
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN,
|
|
|
|
"redis.call('zadd', KEYS[2], ARGV[1], ARGV[3]); " +
|
|
|
|
"local value = redis.call('hexists', KEYS[1], ARGV[3]); " +
|
|
|
|
"if redis.call('hexists', KEYS[1], ARGV[3]) == 0 then " +
|
|
|
|
"if value == 1 then " +
|
|
|
|
"redis.call('hset', KEYS[1], ARGV[3], ARGV[2]); " +
|
|
|
|
"local expireDateScore = redis.call('zscore', KEYS[2], ARGV[3]); "
|
|
|
|
"return 1; " +
|
|
|
|
+ "if expireDateScore ~= false and tonumber(expireDateScore) <= tonumber(ARGV[1]) then "
|
|
|
|
"end;" +
|
|
|
|
+ "redis.call('zadd', KEYS[2], ARGV[2], ARGV[2]); "
|
|
|
|
"return 0; ",
|
|
|
|
+ "return 1;"
|
|
|
|
Arrays.<Object>asList(getName(), getTimeoutSetName()), timeoutDate, objectState, key);
|
|
|
|
+ "else "
|
|
|
|
|
|
|
|
+ "return 0;"
|
|
|
|
|
|
|
|
+ "end; " +
|
|
|
|
|
|
|
|
"end;" +
|
|
|
|
|
|
|
|
"redis.call('zadd', KEYS[2], ARGV[2], ARGV[3]); " +
|
|
|
|
|
|
|
|
"redis.call('hset', KEYS[1], ARGV[3], ARGV[4]); " +
|
|
|
|
|
|
|
|
"return 1; ",
|
|
|
|
|
|
|
|
Arrays.<Object>asList(getName(), getTimeoutSetName()), System.currentTimeMillis(), timeoutDate, key, objectState);
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -342,12 +346,19 @@ public class RedissonSetCache<V> extends RedissonExpirable implements RSetCache<
|
|
|
|
byte[] objectState = encode(value);
|
|
|
|
byte[] objectState = encode(value);
|
|
|
|
byte[] key = hash(objectState);
|
|
|
|
byte[] key = hash(objectState);
|
|
|
|
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN,
|
|
|
|
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN,
|
|
|
|
"if redis.call('hexists', KEYS[1], ARGV[1]) == 0 then " +
|
|
|
|
"local value = redis.call('hexists', KEYS[1], ARGV[2]); " +
|
|
|
|
"redis.call('hset', KEYS[1], ARGV[1], ARGV[2]); " +
|
|
|
|
"if value == 1 then " +
|
|
|
|
"return 1; " +
|
|
|
|
"local expireDateScore = redis.call('zscore', KEYS[2], ARGV[2]); "
|
|
|
|
"end; " +
|
|
|
|
+ "if expireDateScore ~= false and tonumber(expireDateScore) <= tonumber(ARGV[1]) then "
|
|
|
|
"return 0; ",
|
|
|
|
+ "redis.call('zrem', KEYS[2], ARGV[2]); "
|
|
|
|
Arrays.<Object>asList(getName()), key, objectState);
|
|
|
|
+ "return 1;"
|
|
|
|
|
|
|
|
+ "else "
|
|
|
|
|
|
|
|
+ "return 0;"
|
|
|
|
|
|
|
|
+ "end; " +
|
|
|
|
|
|
|
|
"end;" +
|
|
|
|
|
|
|
|
"redis.call('hset', KEYS[1], ARGV[2], ARGV[3]); " +
|
|
|
|
|
|
|
|
"return 1; ",
|
|
|
|
|
|
|
|
Arrays.<Object>asList(getName(), getTimeoutSetName()), System.currentTimeMillis(), key, objectState);
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|