|
|
|
@ -15,7 +15,6 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.redisson;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
|
import java.util.AbstractCollection;
|
|
|
|
@ -86,6 +85,10 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Integer> valueSizeAsync(K key) {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandExecutor.readAsync(getName(), codec, RedisCommands.HSTRLEN, getName(key), key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -101,6 +104,10 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> containsKeyAsync(Object key) {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandExecutor.readAsync(getName(key), codec, RedisCommands.HEXISTS, getName(key), key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -111,6 +118,10 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> containsValueAsync(Object value) {
|
|
|
|
|
if (value == null) {
|
|
|
|
|
throw new NullPointerException("map value can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 4),
|
|
|
|
|
"local s = redis.call('hvals', KEYS[1]);" +
|
|
|
|
|
"for i = 1, #s, 1 do "
|
|
|
|
@ -232,6 +243,13 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<V> putIfAbsentAsync(K key, V value) {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
if (value == null) {
|
|
|
|
|
throw new NullPointerException("map value can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandExecutor.evalWriteAsync(getName(key), codec, EVAL_PUT,
|
|
|
|
|
"if redis.call('hsetnx', KEYS[1], ARGV[1], ARGV[2]) == 1 then "
|
|
|
|
|
+ "return nil "
|
|
|
|
@ -248,6 +266,13 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> fastPutIfAbsentAsync(K key, V value) {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
if (value == null) {
|
|
|
|
|
throw new NullPointerException("map value can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandExecutor.writeAsync(getName(key), codec, RedisCommands.HSETNX, getName(key), key, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -258,6 +283,13 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> removeAsync(Object key, Object value) {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
if (value == null) {
|
|
|
|
|
throw new NullPointerException("map value can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandExecutor.evalWriteAsync(getName(key), codec, EVAL_REMOVE_VALUE,
|
|
|
|
|
"if redis.call('hget', KEYS[1], ARGV[1]) == ARGV[2] then "
|
|
|
|
|
+ "return redis.call('hdel', KEYS[1], ARGV[1]) "
|
|
|
|
@ -274,6 +306,17 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> replaceAsync(K key, V oldValue, V newValue) {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
if (oldValue == null) {
|
|
|
|
|
throw new NullPointerException("map oldValue can't be null");
|
|
|
|
|
}
|
|
|
|
|
if (newValue == null) {
|
|
|
|
|
throw new NullPointerException("map newValue can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return commandExecutor.evalWriteAsync(getName(key), codec, EVAL_REPLACE_VALUE,
|
|
|
|
|
"if redis.call('hget', KEYS[1], ARGV[1]) == ARGV[2] then "
|
|
|
|
|
+ "redis.call('hset', KEYS[1], ARGV[1], ARGV[3]); "
|
|
|
|
@ -291,6 +334,13 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<V> replaceAsync(K key, V value) {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
if (value == null) {
|
|
|
|
|
throw new NullPointerException("map value can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandExecutor.evalWriteAsync(getName(key), codec, EVAL_REPLACE,
|
|
|
|
|
"if redis.call('hexists', KEYS[1], ARGV[1]) == 1 then "
|
|
|
|
|
+ "local v = redis.call('hget', KEYS[1], ARGV[1]); "
|
|
|
|
@ -304,6 +354,10 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<V> getAsync(K key) {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandExecutor.readAsync(getName(key), codec, RedisCommands.HGET, getName(key), key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -313,6 +367,13 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<V> putAsync(K key, V value) {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
if (value == null) {
|
|
|
|
|
throw new NullPointerException("map value can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandExecutor.evalWriteAsync(getName(key), codec, EVAL_PUT,
|
|
|
|
|
"local v = redis.call('hget', KEYS[1], ARGV[1]); "
|
|
|
|
|
+ "redis.call('hset', KEYS[1], ARGV[1], ARGV[2]); "
|
|
|
|
@ -323,6 +384,10 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<V> removeAsync(K key) {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandExecutor.evalWriteAsync(getName(key), codec, EVAL_REMOVE,
|
|
|
|
|
"local v = redis.call('hget', KEYS[1], ARGV[1]); "
|
|
|
|
|
+ "redis.call('hdel', KEYS[1], ARGV[1]); "
|
|
|
|
@ -332,6 +397,13 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Boolean> fastPutAsync(K key, V value) {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
if (value == null) {
|
|
|
|
|
throw new NullPointerException("map value can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandExecutor.writeAsync(getName(key), codec, RedisCommands.HSET, getName(key), key, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -370,14 +442,17 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<V> addAndGetAsync(K key, Number value) {
|
|
|
|
|
try {
|
|
|
|
|
byte[] keyState = codec.getMapKeyEncoder().encode(key);
|
|
|
|
|
if (key == null) {
|
|
|
|
|
throw new NullPointerException("map key can't be null");
|
|
|
|
|
}
|
|
|
|
|
if (value == null) {
|
|
|
|
|
throw new NullPointerException("map value can't be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] keyState = encodeMapKey(key);
|
|
|
|
|
return commandExecutor.writeAsync(getName(key), StringCodec.INSTANCE,
|
|
|
|
|
new RedisCommand<Object>("HINCRBYFLOAT", new NumberConvertor(value.getClass())),
|
|
|
|
|
getName(key), keyState, new BigDecimal(value.toString()).toPlainString());
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new IllegalArgumentException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|