Skip to content

Commit

Permalink
LocalCachedMap should implement RMap interface. #592
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita committed Sep 14, 2016
1 parent db3a661 commit ccaebb2
Show file tree
Hide file tree
Showing 11 changed files with 723 additions and 155 deletions.
526 changes: 435 additions & 91 deletions redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions redisson/src/main/java/org/redisson/RedissonMap.java
Expand Up @@ -38,7 +38,6 @@
import org.redisson.client.protocol.RedisCommand.ValueType; import org.redisson.client.protocol.RedisCommand.ValueType;
import org.redisson.client.protocol.RedisCommands; import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.convertor.BooleanReplayConvertor; import org.redisson.client.protocol.convertor.BooleanReplayConvertor;
import org.redisson.client.protocol.convertor.LongReplayConvertor;
import org.redisson.client.protocol.convertor.NumberConvertor; import org.redisson.client.protocol.convertor.NumberConvertor;
import org.redisson.client.protocol.decoder.MapScanResult; import org.redisson.client.protocol.decoder.MapScanResult;
import org.redisson.client.protocol.decoder.ScanObjectEntry; import org.redisson.client.protocol.decoder.ScanObjectEntry;
Expand All @@ -59,7 +58,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
static final RedisCommand<Object> EVAL_REMOVE = new RedisCommand<Object>("EVAL", 4, ValueType.MAP_KEY, ValueType.MAP_VALUE); static final RedisCommand<Object> EVAL_REMOVE = new RedisCommand<Object>("EVAL", 4, ValueType.MAP_KEY, ValueType.MAP_VALUE);
static final RedisCommand<Object> EVAL_REPLACE = new RedisCommand<Object>("EVAL", 4, ValueType.MAP, ValueType.MAP_VALUE); static final RedisCommand<Object> EVAL_REPLACE = new RedisCommand<Object>("EVAL", 4, ValueType.MAP, ValueType.MAP_VALUE);
static final RedisCommand<Boolean> EVAL_REPLACE_VALUE = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 4, Arrays.asList(ValueType.MAP_KEY, ValueType.MAP_VALUE, ValueType.MAP_VALUE)); static final RedisCommand<Boolean> EVAL_REPLACE_VALUE = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 4, Arrays.asList(ValueType.MAP_KEY, ValueType.MAP_VALUE, ValueType.MAP_VALUE));
static final RedisCommand<Long> EVAL_REMOVE_VALUE = new RedisCommand<Long>("EVAL", new LongReplayConvertor(), 4, ValueType.MAP); static final RedisCommand<Boolean> EVAL_REMOVE_VALUE = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 4, ValueType.MAP);
static final RedisCommand<Object> EVAL_PUT = EVAL_REPLACE; static final RedisCommand<Object> EVAL_PUT = EVAL_REPLACE;


protected RedissonMap(CommandAsyncExecutor commandExecutor, String name) { protected RedissonMap(CommandAsyncExecutor commandExecutor, String name) {
Expand Down Expand Up @@ -244,11 +243,11 @@ public RFuture<Boolean> fastPutIfAbsentAsync(K key, V value) {


@Override @Override
public boolean remove(Object key, Object value) { public boolean remove(Object key, Object value) {
return get(removeAsync(key, value)) == 1; return get(removeAsync(key, value));
} }


@Override @Override
public RFuture<Long> removeAsync(Object key, Object value) { public RFuture<Boolean> removeAsync(Object key, Object value) {
return commandExecutor.evalWriteAsync(getName(key), codec, EVAL_REMOVE_VALUE, return commandExecutor.evalWriteAsync(getName(key), codec, EVAL_REMOVE_VALUE,
"if redis.call('hget', KEYS[1], ARGV[1]) == ARGV[2] then " "if redis.call('hget', KEYS[1], ARGV[1]) == ARGV[2] then "
+ "return redis.call('hdel', KEYS[1], ARGV[1]) " + "return redis.call('hdel', KEYS[1], ARGV[1]) "
Expand Down
8 changes: 2 additions & 6 deletions redisson/src/main/java/org/redisson/RedissonMapCache.java
Expand Up @@ -34,17 +34,14 @@
import org.redisson.client.protocol.RedisCommand.ValueType; import org.redisson.client.protocol.RedisCommand.ValueType;
import org.redisson.client.protocol.RedisCommands; import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.convertor.BooleanReplayConvertor; import org.redisson.client.protocol.convertor.BooleanReplayConvertor;
import org.redisson.client.protocol.convertor.LongReplayConvertor;
import org.redisson.client.protocol.convertor.VoidReplayConvertor; import org.redisson.client.protocol.convertor.VoidReplayConvertor;
import org.redisson.client.protocol.decoder.ListMultiDecoder; import org.redisson.client.protocol.decoder.ListMultiDecoder;
import org.redisson.client.protocol.decoder.LongMultiDecoder; import org.redisson.client.protocol.decoder.LongMultiDecoder;
import org.redisson.client.protocol.decoder.MapCacheScanResult; import org.redisson.client.protocol.decoder.MapCacheScanResult;
import org.redisson.client.protocol.decoder.MapCacheScanResultReplayDecoder; import org.redisson.client.protocol.decoder.MapCacheScanResultReplayDecoder;
import org.redisson.client.protocol.decoder.MapScanResult; import org.redisson.client.protocol.decoder.MapScanResult;
import org.redisson.client.protocol.decoder.ObjectListDecoder; import org.redisson.client.protocol.decoder.ObjectListDecoder;
import org.redisson.client.protocol.decoder.ObjectListReplayDecoder;
import org.redisson.client.protocol.decoder.ObjectMapDecoder; import org.redisson.client.protocol.decoder.ObjectMapDecoder;
import org.redisson.client.protocol.decoder.ObjectMapReplayDecoder;
import org.redisson.client.protocol.decoder.ScanObjectEntry; import org.redisson.client.protocol.decoder.ScanObjectEntry;
import org.redisson.command.CommandAsyncExecutor; import org.redisson.command.CommandAsyncExecutor;
import org.redisson.connection.decoder.MapGetAllDecoder; import org.redisson.connection.decoder.MapGetAllDecoder;
Expand Down Expand Up @@ -77,9 +74,8 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
static final RedisCommand<Object> EVAL_REPLACE = new RedisCommand<Object>("EVAL", 6, ValueType.MAP, ValueType.MAP_VALUE); static final RedisCommand<Object> EVAL_REPLACE = new RedisCommand<Object>("EVAL", 6, ValueType.MAP, ValueType.MAP_VALUE);
static final RedisCommand<Boolean> EVAL_REPLACE_VALUE = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 7, Arrays.asList(ValueType.MAP_KEY, ValueType.MAP_VALUE, ValueType.MAP_VALUE)); static final RedisCommand<Boolean> EVAL_REPLACE_VALUE = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 7, Arrays.asList(ValueType.MAP_KEY, ValueType.MAP_VALUE, ValueType.MAP_VALUE));
private static final RedisCommand<Void> EVAL_HMSET = new RedisCommand<Void>("EVAL", new VoidReplayConvertor(), 4, ValueType.MAP); private static final RedisCommand<Void> EVAL_HMSET = new RedisCommand<Void>("EVAL", new VoidReplayConvertor(), 4, ValueType.MAP);
private static final RedisCommand<MapCacheScanResult<Object, Object>> EVAL_HSCAN = new RedisCommand<MapCacheScanResult<Object, Object>>("EVAL", new ListMultiDecoder(new LongMultiDecoder(), new ObjectMapReplayDecoder(), new ObjectListReplayDecoder()), ValueType.MAP);
private static final RedisCommand<Object> EVAL_REMOVE = new RedisCommand<Object>("EVAL", 4, ValueType.MAP_KEY, ValueType.MAP_VALUE); private static final RedisCommand<Object> EVAL_REMOVE = new RedisCommand<Object>("EVAL", 4, ValueType.MAP_KEY, ValueType.MAP_VALUE);
private static final RedisCommand<Long> EVAL_REMOVE_VALUE = new RedisCommand<Long>("EVAL", new LongReplayConvertor(), 5, ValueType.MAP); private static final RedisCommand<Boolean> EVAL_REMOVE_VALUE = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 5, ValueType.MAP);
private static final RedisCommand<Object> EVAL_PUT_TTL = new RedisCommand<Object>("EVAL", 9, ValueType.MAP, ValueType.MAP_VALUE); private static final RedisCommand<Object> EVAL_PUT_TTL = new RedisCommand<Object>("EVAL", 9, ValueType.MAP, ValueType.MAP_VALUE);
private static final RedisCommand<Boolean> EVAL_FAST_PUT_TTL = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 9, ValueType.MAP, ValueType.MAP_VALUE); private static final RedisCommand<Boolean> EVAL_FAST_PUT_TTL = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 9, ValueType.MAP, ValueType.MAP_VALUE);
private static final RedisCommand<Object> EVAL_GET_TTL = new RedisCommand<Object>("EVAL", 7, ValueType.MAP_KEY, ValueType.MAP_VALUE); private static final RedisCommand<Object> EVAL_GET_TTL = new RedisCommand<Object>("EVAL", 7, ValueType.MAP_KEY, ValueType.MAP_VALUE);
Expand Down Expand Up @@ -283,7 +279,7 @@ public RFuture<V> putIfAbsentAsync(K key, V value, long ttl, TimeUnit ttlUnit, l
} }


@Override @Override
public RFuture<Long> removeAsync(Object key, Object value) { public RFuture<Boolean> removeAsync(Object key, Object value) {
return commandExecutor.evalWriteAsync(getName(), codec, EVAL_REMOVE_VALUE, return commandExecutor.evalWriteAsync(getName(), codec, EVAL_REMOVE_VALUE,
"local value = redis.call('hget', KEYS[1], ARGV[1]); " "local value = redis.call('hget', KEYS[1], ARGV[1]); "
+ "if value == false then " + "if value == false then "
Expand Down
29 changes: 1 addition & 28 deletions redisson/src/main/java/org/redisson/api/RLocalCachedMap.java
Expand Up @@ -15,8 +15,6 @@
*/ */
package org.redisson.api; package org.redisson.api;


import java.util.Map;

/** /**
* Map object with entry cache support. * Map object with entry cache support.
* <p> * <p>
Expand All @@ -28,31 +26,6 @@
* @param <K> * @param <K>
* @param <V> * @param <V>
*/ */
public interface RLocalCachedMap<K, V> extends Map<K, V>, RExpirable, RLocalCachedMapAsync<K, V>, RDestroyable { public interface RLocalCachedMap<K, V> extends RMap<K, V>, RExpirable, RDestroyable {


/**
* Associates the specified <code>value</code> with the specified <code>key</code>.
* <p>
* Works faster than <code>RLocalCachedMap.put</code> but not returning
* the previous value associated with <code>key</code>
*
* @param key
* @param value
* @return <code>true</code> if key is a new key in the hash and value was set.
* <code>false</code> if key already exists in the hash and the value was updated.
*/
boolean fastPut(K key, V value);

/**
* Removes <code>key</code> from map
* <p>
* Works faster than <code>RLocalCachedMap.remove</code> but not returning
* the value associated with <code>key</code>
*
* @param key
* @return <code>true</code> if key has been deleted.
* <code>false</code> if key doesn't exist.
*/
boolean fastRemove(Object key);

} }
2 changes: 1 addition & 1 deletion redisson/src/main/java/org/redisson/api/RMapAsync.java
Expand Up @@ -100,7 +100,7 @@ public interface RMapAsync<K, V> extends RExpirableAsync {


RFuture<Boolean> replaceAsync(K key, V oldValue, V newValue); RFuture<Boolean> replaceAsync(K key, V oldValue, V newValue);


RFuture<Long> removeAsync(Object key, Object value); RFuture<Boolean> removeAsync(Object key, Object value);


RFuture<V> putIfAbsentAsync(K key, V value); RFuture<V> putIfAbsentAsync(K key, V value);


Expand Down
2 changes: 1 addition & 1 deletion redisson/src/main/java/org/redisson/api/RMapReactive.java
Expand Up @@ -77,7 +77,7 @@ public interface RMapReactive<K, V> extends RExpirableReactive {


Publisher<Boolean> replace(K key, V oldValue, V newValue); Publisher<Boolean> replace(K key, V oldValue, V newValue);


Publisher<Long> remove(Object key, Object value); Publisher<Boolean> remove(Object key, Object value);


Publisher<V> putIfAbsent(K key, V value); Publisher<V> putIfAbsent(K key, V value);


Expand Down
Expand Up @@ -36,7 +36,6 @@
import org.redisson.client.protocol.RedisCommands; import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.convertor.BooleanReplayConvertor; import org.redisson.client.protocol.convertor.BooleanReplayConvertor;
import org.redisson.client.protocol.convertor.Convertor; import org.redisson.client.protocol.convertor.Convertor;
import org.redisson.client.protocol.convertor.LongReplayConvertor;
import org.redisson.client.protocol.decoder.MapScanResult; import org.redisson.client.protocol.decoder.MapScanResult;
import org.redisson.client.protocol.decoder.MapScanResultReplayDecoder; import org.redisson.client.protocol.decoder.MapScanResultReplayDecoder;
import org.redisson.client.protocol.decoder.NestedMultiDecoder; import org.redisson.client.protocol.decoder.NestedMultiDecoder;
Expand Down Expand Up @@ -74,7 +73,7 @@ public class RedissonMapCacheReactive<K, V> extends RedissonMapReactive<K, V> im


private static final RedisCommand<MapScanResult<Object, Object>> EVAL_HSCAN = new RedisCommand<MapScanResult<Object, Object>>("EVAL", new NestedMultiDecoder(new ObjectMapReplayDecoder(), new MapScanResultReplayDecoder()), ValueType.MAP); private static final RedisCommand<MapScanResult<Object, Object>> EVAL_HSCAN = new RedisCommand<MapScanResult<Object, Object>>("EVAL", new NestedMultiDecoder(new ObjectMapReplayDecoder(), new MapScanResultReplayDecoder()), ValueType.MAP);
private static final RedisCommand<Object> EVAL_REMOVE = new RedisCommand<Object>("EVAL", 4, ValueType.MAP_KEY, ValueType.MAP_VALUE); private static final RedisCommand<Object> EVAL_REMOVE = new RedisCommand<Object>("EVAL", 4, ValueType.MAP_KEY, ValueType.MAP_VALUE);
private static final RedisCommand<Long> EVAL_REMOVE_VALUE = new RedisCommand<Long>("EVAL", new LongReplayConvertor(), 5, ValueType.MAP); private static final RedisCommand<Boolean> EVAL_REMOVE_VALUE = new RedisCommand<Boolean>("EVAL", new BooleanReplayConvertor(), 5, ValueType.MAP);
private static final RedisCommand<Object> EVAL_PUT_TTL = new RedisCommand<Object>("EVAL", 6, ValueType.MAP, ValueType.MAP_VALUE); private static final RedisCommand<Object> EVAL_PUT_TTL = new RedisCommand<Object>("EVAL", 6, ValueType.MAP, ValueType.MAP_VALUE);
private static final RedisCommand<List<Object>> EVAL_GET_TTL = new RedisCommand<List<Object>>("EVAL", new TTLMapValueReplayDecoder<Object>(), 5, ValueType.MAP_KEY, ValueType.MAP_VALUE); private static final RedisCommand<List<Object>> EVAL_GET_TTL = new RedisCommand<List<Object>>("EVAL", new TTLMapValueReplayDecoder<Object>(), 5, ValueType.MAP_KEY, ValueType.MAP_VALUE);
private static final RedisCommand<List<Object>> EVAL_CONTAINS_KEY = new RedisCommand<List<Object>>("EVAL", new ObjectListReplayDecoder<Object>(), 5, ValueType.MAP_KEY); private static final RedisCommand<List<Object>> EVAL_CONTAINS_KEY = new RedisCommand<List<Object>>("EVAL", new ObjectListReplayDecoder<Object>(), 5, ValueType.MAP_KEY);
Expand Down Expand Up @@ -225,7 +224,7 @@ public Publisher<V> putIfAbsent(K key, V value, long ttl, TimeUnit unit) {
} }


@Override @Override
public Publisher<Long> remove(Object key, Object value) { public Publisher<Boolean> remove(Object key, Object value) {
return commandExecutor.evalWriteReactive(getName(), codec, EVAL_REMOVE_VALUE, return commandExecutor.evalWriteReactive(getName(), codec, EVAL_REMOVE_VALUE,
"if redis.call('hget', KEYS[1], ARGV[1]) == ARGV[2] then " "if redis.call('hget', KEYS[1], ARGV[1]) == ARGV[2] then "
+ "redis.call('zrem', KEYS[2], ARGV[1]); " + "redis.call('zrem', KEYS[2], ARGV[1]); "
Expand Down
Expand Up @@ -78,6 +78,7 @@ public Publisher<Map<K, V>> getAll(Set<K> keys) {
return reactive(instance.getAllAsync(keys)); return reactive(instance.getAllAsync(keys));
} }


@Override
public Publisher<Void> putAll(Map<? extends K, ? extends V> map) { public Publisher<Void> putAll(Map<? extends K, ? extends V> map) {
return reactive(instance.putAllAsync(map)); return reactive(instance.putAllAsync(map));
} }
Expand All @@ -88,7 +89,7 @@ public Publisher<V> putIfAbsent(K key, V value) {
} }


@Override @Override
public Publisher<Long> remove(Object key, Object value) { public Publisher<Boolean> remove(Object key, Object value) {
return reactive(instance.removeAsync(key, value)); return reactive(instance.removeAsync(key, value));
} }


Expand Down

0 comments on commit ccaebb2

Please sign in to comment.