refactoring

pull/1253/merge
Nikita 7 years ago
parent bf68267931
commit 9d845c1172

@ -42,13 +42,17 @@ public class RedissonListMultimapCache<K, V> extends RedissonListMultimap<K, V>
RedissonListMultimapCache(EvictionScheduler evictionScheduler, CommandAsyncExecutor connectionManager, String name) { RedissonListMultimapCache(EvictionScheduler evictionScheduler, CommandAsyncExecutor connectionManager, String name) {
super(connectionManager, name); super(connectionManager, name);
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName()); if (evictionScheduler != null) {
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName());
}
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix); baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix);
} }
RedissonListMultimapCache(EvictionScheduler evictionScheduler, Codec codec, CommandAsyncExecutor connectionManager, String name) { RedissonListMultimapCache(EvictionScheduler evictionScheduler, Codec codec, CommandAsyncExecutor connectionManager, String name) {
super(codec, connectionManager, name); super(codec, connectionManager, name);
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName()); if (evictionScheduler != null) {
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName());
}
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix); baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix);
} }

@ -237,7 +237,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
return options == null || options.getLoader() == null; return options == null || options.getLoader() == null;
} }
protected RFuture<Map<K, V>> getAllOperationAsync(Set<K> keys) { public RFuture<Map<K, V>> getAllOperationAsync(Set<K> keys) {
List<Object> args = new ArrayList<Object>(keys.size() + 1); List<Object> args = new ArrayList<Object>(keys.size() + 1);
args.add(getName()); args.add(getName());
encodeMapKeys(args, keys); encodeMapKeys(args, keys);
@ -624,7 +624,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
Collections.<Object>singletonList(getName(key)), encodeMapKey(key), encodeMapValue(value)); Collections.<Object>singletonList(getName(key)), encodeMapKey(key), encodeMapValue(value));
} }
protected RFuture<V> getOperationAsync(K key) { public RFuture<V> getOperationAsync(K key) {
return commandExecutor.readAsync(getName(key), codec, RedisCommands.HGET, getName(key), encodeMapKey(key)); return commandExecutor.readAsync(getName(key), codec, RedisCommands.HGET, getName(key), encodeMapKey(key));
} }
@ -973,7 +973,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
return get(fastRemoveAsync(keys)); return get(fastRemoveAsync(keys));
} }
MapScanResult<ScanObjectEntry, ScanObjectEntry> scanIterator(String name, RedisClient client, long startPos, String pattern) { public MapScanResult<ScanObjectEntry, ScanObjectEntry> scanIterator(String name, RedisClient client, long startPos, String pattern) {
if (pattern == null) { if (pattern == null) {
RFuture<MapScanResult<ScanObjectEntry, ScanObjectEntry>> f RFuture<MapScanResult<ScanObjectEntry, ScanObjectEntry>> f
= commandExecutor.readAsync(client, name, new MapScanCodec(codec), RedisCommands.HSCAN, name, startPos); = commandExecutor.readAsync(client, name, new MapScanCodec(codec), RedisCommands.HSCAN, name, startPos);

@ -210,7 +210,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
} }
@Override @Override
protected RFuture<Map<K, V>> getAllOperationAsync(Set<K> keys) { public RFuture<Map<K, V>> getAllOperationAsync(Set<K> keys) {
List<Object> args = new ArrayList<Object>(keys.size() + 1); List<Object> args = new ArrayList<Object>(keys.size() + 1);
List<Object> plainKeys = new ArrayList<Object>(keys.size()); List<Object> plainKeys = new ArrayList<Object>(keys.size());
@ -448,7 +448,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
} }
@Override @Override
protected RFuture<V> getOperationAsync(K key) { public RFuture<V> getOperationAsync(K key) {
return commandExecutor.evalWriteAsync(getName(key), codec, RedisCommands.EVAL_MAP_VALUE, return commandExecutor.evalWriteAsync(getName(key), codec, RedisCommands.EVAL_MAP_VALUE,
"local value = redis.call('hget', KEYS[1], ARGV[2]); " "local value = redis.call('hget', KEYS[1], ARGV[2]); "
+ "if value == false then " + "if value == false then "
@ -618,7 +618,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
} }
@Override @Override
public RFuture<V> addAndGetOperationAsync(K key, Number value) { protected RFuture<V> addAndGetOperationAsync(K key, Number value) {
ByteBuf keyState = encodeMapKey(key); ByteBuf keyState = encodeMapKey(key);
return commandExecutor.evalWriteAsync(getName(key), StringCodec.INSTANCE, return commandExecutor.evalWriteAsync(getName(key), StringCodec.INSTANCE,
new RedisCommand<Object>("EVAL", new NumberConvertor(value.getClass())), new RedisCommand<Object>("EVAL", new NumberConvertor(value.getClass())),
@ -1100,7 +1100,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
@Override @Override
public RFuture<V> removeOperationAsync(K key) { protected RFuture<V> removeOperationAsync(K key) {
return commandExecutor.evalWriteAsync(getName(key), codec, RedisCommands.EVAL_MAP_VALUE, return commandExecutor.evalWriteAsync(getName(key), codec, RedisCommands.EVAL_MAP_VALUE,
"local value = redis.call('hget', KEYS[1], ARGV[2]); " "local value = redis.call('hget', KEYS[1], ARGV[2]); "
+ "if value == false then " + "if value == false then "
@ -1198,7 +1198,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
} }
@Override @Override
MapScanResult<ScanObjectEntry, ScanObjectEntry> scanIterator(String name, RedisClient client, long startPos, String pattern) { public MapScanResult<ScanObjectEntry, ScanObjectEntry> scanIterator(String name, RedisClient client, long startPos, String pattern) {
return get(scanIteratorAsync(name, client, startPos, pattern)); return get(scanIteratorAsync(name, client, startPos, pattern));
} }
@ -1635,7 +1635,7 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
} }
@Override @Override
public RFuture<Void> putAllOperationAsync(Map<? extends K, ? extends V> map) { protected RFuture<Void> putAllOperationAsync(Map<? extends K, ? extends V> map) {
List<Object> params = new ArrayList<Object>(map.size()*2 + 1); List<Object> params = new ArrayList<Object>(map.size()*2 + 1);
params.add(System.currentTimeMillis()); params.add(System.currentTimeMillis());
for (java.util.Map.Entry<? extends K, ? extends V> t : map.entrySet()) { for (java.util.Map.Entry<? extends K, ? extends V> t : map.entrySet()) {

@ -56,14 +56,14 @@ public abstract class RedissonObject implements RObject {
return commandExecutor.await(future, timeout, timeoutUnit); return commandExecutor.await(future, timeout, timeoutUnit);
} }
protected static String prefixName(String prefix, String name) { public static String prefixName(String prefix, String name) {
if (name.contains("{")) { if (name.contains("{")) {
return prefix + ":" + name; return prefix + ":" + name;
} }
return prefix + ":{" + name + "}"; return prefix + ":{" + name + "}";
} }
protected static String suffixName(String name, String suffix) { public static String suffixName(String name, String suffix) {
if (name.contains("{")) { if (name.contains("{")) {
return name + ":" + suffix; return name + ":" + suffix;
} }
@ -194,7 +194,7 @@ public abstract class RedissonObject implements RObject {
} }
} }
protected ByteBuf encode(Object value) { public ByteBuf encode(Object value) {
if (commandExecutor.isRedissonReferenceSupportEnabled()) { if (commandExecutor.isRedissonReferenceSupportEnabled()) {
RedissonReference reference = RedissonObjectFactory.toReference(commandExecutor.getConnectionManager().getCfg(), value); RedissonReference reference = RedissonObjectFactory.toReference(commandExecutor.getConnectionManager().getCfg(), value);
if (reference != null) { if (reference != null) {
@ -209,7 +209,7 @@ public abstract class RedissonObject implements RObject {
} }
} }
protected ByteBuf encodeMapKey(Object value) { public ByteBuf encodeMapKey(Object value) {
if (commandExecutor.isRedissonReferenceSupportEnabled()) { if (commandExecutor.isRedissonReferenceSupportEnabled()) {
RedissonReference reference = RedissonObjectFactory.toReference(commandExecutor.getConnectionManager().getCfg(), value); RedissonReference reference = RedissonObjectFactory.toReference(commandExecutor.getConnectionManager().getCfg(), value);
if (reference != null) { if (reference != null) {
@ -224,7 +224,7 @@ public abstract class RedissonObject implements RObject {
} }
} }
protected ByteBuf encodeMapValue(Object value) { public ByteBuf encodeMapValue(Object value) {
if (commandExecutor.isRedissonReferenceSupportEnabled()) { if (commandExecutor.isRedissonReferenceSupportEnabled()) {
RedissonReference reference = RedissonObjectFactory.toReference(commandExecutor.getConnectionManager().getCfg(), value); RedissonReference reference = RedissonObjectFactory.toReference(commandExecutor.getConnectionManager().getCfg(), value);
if (reference != null) { if (reference != null) {

@ -41,13 +41,17 @@ public class RedissonSetMultimapCache<K, V> extends RedissonSetMultimap<K, V> im
RedissonSetMultimapCache(EvictionScheduler evictionScheduler, CommandAsyncExecutor connectionManager, String name) { RedissonSetMultimapCache(EvictionScheduler evictionScheduler, CommandAsyncExecutor connectionManager, String name) {
super(connectionManager, name); super(connectionManager, name);
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName()); if (evictionScheduler != null) {
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName());
}
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix); baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix);
} }
RedissonSetMultimapCache(EvictionScheduler evictionScheduler, Codec codec, CommandAsyncExecutor connectionManager, String name) { RedissonSetMultimapCache(EvictionScheduler evictionScheduler, Codec codec, CommandAsyncExecutor connectionManager, String name) {
super(codec, connectionManager, name); super(codec, connectionManager, name);
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName()); if (evictionScheduler != null) {
evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName());
}
baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix); baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix);
} }

Loading…
Cancel
Save