From 39ade6f3abdad492909c4963b1b5700773d0b643 Mon Sep 17 00:00:00 2001 From: Redkale Date: Sun, 15 Jan 2023 19:39:04 +0800 Subject: [PATCH] =?UTF-8?q?CacheSource=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/redkale/source/CacheMemorySource.java | 403 +++++++++--------- .../java/org/redkale/source/CacheSource.java | 64 ++- 2 files changed, 233 insertions(+), 234 deletions(-) diff --git a/src/main/java/org/redkale/source/CacheMemorySource.java b/src/main/java/org/redkale/source/CacheMemorySource.java index 6b1ce5acb..dbda392de 100644 --- a/src/main/java/org/redkale/source/CacheMemorySource.java +++ b/src/main/java/org/redkale/source/CacheMemorySource.java @@ -1130,11 +1130,6 @@ public final class CacheMemorySource extends AbstractCacheSource { return CompletableFuture.supplyAsync(() -> del(keys), getExecutor()).whenComplete(futureCompleteConsumer); } - @Override - public Collection getCollection(final String key, final Type componentType) { - return (Collection) get(key, componentType); - } - @Override public Set smembers(final String key, final Type componentType) { return (Set) get(key, componentType); @@ -1169,66 +1164,6 @@ public final class CacheMemorySource extends AbstractCacheSource { return map; } - @Override - public Map> getCollectionMap(final boolean set, final Type componentType, final String... keys) { - Map> map = new HashMap<>(); - for (String key : keys) { - Collection s = (Collection) get(key, componentType); - if (s != null) { - map.put(key, s); - } - } - return map; - } - - @Override - public Collection getStringCollection(final String key) { - return (Collection) get(key, String.class); - } - - @Override - public Map> getStringCollectionMap(final boolean set, final String... keys) { - Map> map = new HashMap<>(); - for (String key : keys) { - Collection s = (Collection) get(key, String.class); - if (s != null) { - map.put(key, s); - } - } - return map; - } - - @Override - public Map getLongMap(final String... keys) { - Map map = new LinkedHashMap<>(); - for (String key : keys) { - Number n = (Number) get(key, long.class); - map.put(key, n == null ? null : n.longValue()); - } - return map; - } - - @Override - public Long[] getLongArray(final String... keys) { - Long[] rs = new Long[keys.length]; - int index = -1; - for (String key : keys) { - Number n = (Number) get(key, long.class); - rs[++index] = n == null ? null : n.longValue(); - } - return rs; - } - - @Override - public CompletableFuture> getLongMapAsync(final String... keys) { - return CompletableFuture.supplyAsync(() -> getLongMap(keys), getExecutor()); - } - - @Override - public CompletableFuture getLongArrayAsync(final String... keys) { - return CompletableFuture.supplyAsync(() -> getLongArray(keys), getExecutor()); - } - @Override public Map mget(final Type componentType, final String... keys) { Map map = new LinkedHashMap<>(); @@ -1288,68 +1223,6 @@ public final class CacheMemorySource extends AbstractCacheSource { return CompletableFuture.completedFuture(mgetBytes(keys)); } - @Override - public Map getStringMap(final String... keys) { - Map map = new LinkedHashMap<>(); - for (String key : keys) { - Object n = get(key, String.class); - map.put(key, n == null ? null : n.toString()); - } - return map; - } - - @Override - public String[] getStringArray(final String... keys) { - String[] rs = new String[keys.length]; - int index = -1; - for (String key : keys) { - Object n = get(key, String.class); - rs[++index] = n == null ? null : n.toString(); - } - return rs; - } - - @Override - public CompletableFuture> getStringMapAsync(final String... keys) { - return CompletableFuture.supplyAsync(() -> getStringMap(keys), getExecutor()); - } - - @Override - public CompletableFuture getStringArrayAsync(final String... keys) { - return CompletableFuture.supplyAsync(() -> getStringArray(keys), getExecutor()); - } - - @Override - public Map getMap(final Type componentType, final String... keys) { - Map map = new LinkedHashMap<>(); - for (String key : keys) { - map.put(key, (T) get(key, componentType)); - } - return map; - } - - @Override - public CompletableFuture> getMapAsync(final Type componentType, final String... keys) { - return CompletableFuture.supplyAsync(() -> getMap(componentType, keys), getExecutor()); - } - - @Override - public Collection getLongCollection(final String key) { - return (Collection) get(key, long.class); - } - - @Override - public Map> getLongCollectionMap(final boolean set, final String... keys) { - Map> map = new HashMap<>(); - for (String key : keys) { - Collection s = (Collection) get(key, long.class); - if (s != null) { - map.put(key, s); - } - } - return map; - } - @Override public CompletableFuture>> lrangeAsync(Type componentType, String... keys) { return CompletableFuture.supplyAsync(() -> lrange(componentType, keys), getExecutor()); @@ -1360,36 +1233,6 @@ public final class CacheMemorySource extends AbstractCacheSource { return CompletableFuture.supplyAsync(() -> smembers(componentType, keys), getExecutor()); } - @Override - public CompletableFuture>> getCollectionMapAsync(boolean set, Type componentType, String... keys) { - return CompletableFuture.supplyAsync(() -> getCollectionMap(set, componentType, keys), getExecutor()); - } - - @Override - public CompletableFuture> getStringCollectionAsync(final String key) { - return CompletableFuture.supplyAsync(() -> getStringCollection(key), getExecutor()); - } - - @Override - public CompletableFuture>> getStringCollectionMapAsync(final boolean set, final String... keys) { - return CompletableFuture.supplyAsync(() -> getStringCollectionMap(set, keys), getExecutor()); - } - - @Override - public CompletableFuture> getLongCollectionAsync(final String key) { - return CompletableFuture.supplyAsync(() -> getLongCollection(key), getExecutor()); - } - - @Override - public CompletableFuture>> getLongCollectionMapAsync(final boolean set, final String... keys) { - return CompletableFuture.supplyAsync(() -> getLongCollectionMap(set, keys), getExecutor()); - } - - @Override - public CompletableFuture> getCollectionAsync(String key, Type componentType) { - return CompletableFuture.supplyAsync(() -> getCollection(key, componentType), getExecutor()); - } - @Override public CompletableFuture> smembersAsync(String key, Type componentType) { return CompletableFuture.supplyAsync(() -> smembers(key, componentType), getExecutor()); @@ -1400,12 +1243,6 @@ public final class CacheMemorySource extends AbstractCacheSource { return CompletableFuture.supplyAsync(() -> lrange(key, componentType), getExecutor()); } - @Override - public int getCollectionSize(final String key) { - Collection collection = (Collection) get(key, Object.class); - return collection == null ? 0 : collection.size(); - } - @Override public int llen(final String key) { Collection collection = (Collection) get(key, Object.class); @@ -1428,24 +1265,9 @@ public final class CacheMemorySource extends AbstractCacheSource { return CompletableFuture.supplyAsync(() -> scard(key), getExecutor()); } - @Override - public CompletableFuture getCollectionSizeAsync(final String key) { - return CompletableFuture.supplyAsync(() -> getCollectionSize(key), getExecutor()); - } - - @Override - public Collection getexCollection(final String key, final int expireSeconds, final Type componentType) { - return (Collection) getex(key, expireSeconds, componentType); - } - - @Override - public Collection getexStringCollection(final String key, final int expireSeconds) { - return (Collection) getex(key, expireSeconds, String.class); - } - @Override public boolean sismember(final String key, final Type type, final T value) { - Collection list = getCollection(key, type); + Collection list = get(key, type); return list != null && list.contains(value); } @@ -1456,7 +1278,7 @@ public final class CacheMemorySource extends AbstractCacheSource { @Override public boolean sismemberString(final String key, final String value) { - Collection list = getStringCollection(key); + Collection list = (Collection) get(key, String.class); return list != null && list.contains(value); } @@ -1467,7 +1289,7 @@ public final class CacheMemorySource extends AbstractCacheSource { @Override public boolean sismemberLong(final String key, final long value) { - Collection list = getLongCollection(key); + Collection list = (Collection) get(key, long.class); return list != null && list.contains(value); } @@ -1476,26 +1298,6 @@ public final class CacheMemorySource extends AbstractCacheSource { return CompletableFuture.supplyAsync(() -> sismemberLong(key, value), getExecutor()); } - @Override - public Collection getexLongCollection(String key, int expireSeconds) { - return (Collection) getex(key, expireSeconds, long.class); - } - - @Override - public CompletableFuture> getexCollectionAsync(final String key, final int expireSeconds, final Type componentType) { - return CompletableFuture.supplyAsync(() -> getexCollection(key, expireSeconds, componentType), getExecutor()); - } - - @Override - public CompletableFuture> getexStringCollectionAsync(final String key, final int expireSeconds) { - return CompletableFuture.supplyAsync(() -> getexStringCollection(key, expireSeconds), getExecutor()); - } - - @Override - public CompletableFuture> getexLongCollectionAsync(final String key, final int expireSeconds) { - return CompletableFuture.supplyAsync(() -> getexLongCollection(key, expireSeconds), getExecutor()); - } - protected void appendListItem(CacheEntryType cacheType, String key, Object value) { if (key == null) { return; @@ -2023,4 +1825,203 @@ public final class CacheMemorySource extends AbstractCacheSource { return mapValue; } } + + @Override + public Collection getexLongCollection(String key, int expireSeconds) { + return (Collection) getex(key, expireSeconds, long.class); + } + + @Override + public CompletableFuture> getexCollectionAsync(final String key, final int expireSeconds, final Type componentType) { + return CompletableFuture.supplyAsync(() -> getexCollection(key, expireSeconds, componentType), getExecutor()); + } + + @Override + public CompletableFuture> getexStringCollectionAsync(final String key, final int expireSeconds) { + return CompletableFuture.supplyAsync(() -> getexStringCollection(key, expireSeconds), getExecutor()); + } + + @Override + public CompletableFuture> getexLongCollectionAsync(final String key, final int expireSeconds) { + return CompletableFuture.supplyAsync(() -> getexLongCollection(key, expireSeconds), getExecutor()); + } + + @Override + public CompletableFuture>> getCollectionMapAsync(boolean set, Type componentType, String... keys) { + return CompletableFuture.supplyAsync(() -> getCollectionMap(set, componentType, keys), getExecutor()); + } + + @Override + public CompletableFuture> getStringCollectionAsync(final String key) { + return CompletableFuture.supplyAsync(() -> getStringCollection(key), getExecutor()); + } + + @Override + public CompletableFuture>> getStringCollectionMapAsync(final boolean set, final String... keys) { + return CompletableFuture.supplyAsync(() -> getStringCollectionMap(set, keys), getExecutor()); + } + + @Override + public CompletableFuture> getLongCollectionAsync(final String key) { + return CompletableFuture.supplyAsync(() -> getLongCollection(key), getExecutor()); + } + + @Override + public CompletableFuture>> getLongCollectionMapAsync(final boolean set, final String... keys) { + return CompletableFuture.supplyAsync(() -> getLongCollectionMap(set, keys), getExecutor()); + } + + @Override + public CompletableFuture> getCollectionAsync(String key, Type componentType) { + return CompletableFuture.supplyAsync(() -> getCollection(key, componentType), getExecutor()); + } + + @Override + public Collection getCollection(final String key, final Type componentType) { + return (Collection) get(key, componentType); + } + + @Override + public Map> getCollectionMap(final boolean set, final Type componentType, final String... keys) { + Map> map = new HashMap<>(); + for (String key : keys) { + Collection s = (Collection) get(key, componentType); + if (s != null) { + map.put(key, s); + } + } + return map; + } + + @Override + public Collection getStringCollection(final String key) { + return (Collection) get(key, String.class); + } + + @Override + public Map> getStringCollectionMap(final boolean set, final String... keys) { + Map> map = new HashMap<>(); + for (String key : keys) { + Collection s = (Collection) get(key, String.class); + if (s != null) { + map.put(key, s); + } + } + return map; + } + + @Override + public Map getLongMap(final String... keys) { + Map map = new LinkedHashMap<>(); + for (String key : keys) { + Number n = (Number) get(key, long.class); + map.put(key, n == null ? null : n.longValue()); + } + return map; + } + + @Override + public Long[] getLongArray(final String... keys) { + Long[] rs = new Long[keys.length]; + int index = -1; + for (String key : keys) { + Number n = (Number) get(key, long.class); + rs[++index] = n == null ? null : n.longValue(); + } + return rs; + } + + @Override + public CompletableFuture> getLongMapAsync(final String... keys) { + return CompletableFuture.supplyAsync(() -> getLongMap(keys), getExecutor()); + } + + @Override + public CompletableFuture getLongArrayAsync(final String... keys) { + return CompletableFuture.supplyAsync(() -> getLongArray(keys), getExecutor()); + } + + @Override + public Map getStringMap(final String... keys) { + Map map = new LinkedHashMap<>(); + for (String key : keys) { + Object n = get(key, String.class); + map.put(key, n == null ? null : n.toString()); + } + return map; + } + + @Override + public String[] getStringArray(final String... keys) { + String[] rs = new String[keys.length]; + int index = -1; + for (String key : keys) { + Object n = get(key, String.class); + rs[++index] = n == null ? null : n.toString(); + } + return rs; + } + + @Override + public CompletableFuture> getStringMapAsync(final String... keys) { + return CompletableFuture.supplyAsync(() -> getStringMap(keys), getExecutor()); + } + + @Override + public CompletableFuture getStringArrayAsync(final String... keys) { + return CompletableFuture.supplyAsync(() -> getStringArray(keys), getExecutor()); + } + + @Override + public Map getMap(final Type componentType, final String... keys) { + Map map = new LinkedHashMap<>(); + for (String key : keys) { + map.put(key, (T) get(key, componentType)); + } + return map; + } + + @Override + public CompletableFuture> getMapAsync(final Type componentType, final String... keys) { + return CompletableFuture.supplyAsync(() -> getMap(componentType, keys), getExecutor()); + } + + @Override + public Collection getLongCollection(final String key) { + return (Collection) get(key, long.class); + } + + @Override + public Map> getLongCollectionMap(final boolean set, final String... keys) { + Map> map = new HashMap<>(); + for (String key : keys) { + Collection s = (Collection) get(key, long.class); + if (s != null) { + map.put(key, s); + } + } + return map; + } + + @Override + public int getCollectionSize(final String key) { + Collection collection = (Collection) get(key, Object.class); + return collection == null ? 0 : collection.size(); + } + + @Override + public CompletableFuture getCollectionSizeAsync(final String key) { + return CompletableFuture.supplyAsync(() -> getCollectionSize(key), getExecutor()); + } + + @Override + public Collection getexCollection(final String key, final int expireSeconds, final Type componentType) { + return (Collection) getex(key, expireSeconds, componentType); + } + + @Override + public Collection getexStringCollection(final String key, final int expireSeconds) { + return (Collection) getex(key, expireSeconds, String.class); + } + } diff --git a/src/main/java/org/redkale/source/CacheSource.java b/src/main/java/org/redkale/source/CacheSource.java index aa626a263..07755d520 100644 --- a/src/main/java/org/redkale/source/CacheSource.java +++ b/src/main/java/org/redkale/source/CacheSource.java @@ -310,37 +310,6 @@ public interface CacheSource extends Resourcable { public long dbsize(); - //------------------------ collection ------------------------ - @Deprecated(since = "2.8.0") - public Collection getCollection(final String key, final Type componentType); - - @Deprecated(since = "2.8.0") - public Map> getCollectionMap(final boolean set, final Type componentType, final String... keys); - - @Deprecated(since = "2.8.0") - public int getCollectionSize(final String key); - - @Deprecated(since = "2.8.0") - public Collection getexCollection(final String key, final int expireSeconds, final Type componentType); - - @Deprecated(since = "2.8.0") - public Map> getStringCollectionMap(final boolean set, final String... keys); - - @Deprecated(since = "2.8.0") - public Collection getStringCollection(final String key); - - @Deprecated(since = "2.8.0") - public Collection getexStringCollection(final String key, final int expireSeconds); - - @Deprecated(since = "2.8.0") - public Collection getLongCollection(final String key); - - @Deprecated(since = "2.8.0") - public Map> getLongCollectionMap(final boolean set, final String... keys); - - @Deprecated(since = "2.8.0") - public Collection getexLongCollection(final String key, final int expireSeconds); - //---------------------- CompletableFuture 异步版 --------------------------------- default CompletableFuture isOpenAsync() { return CompletableFuture.completedFuture(isOpen()); @@ -622,7 +591,37 @@ public interface CacheSource extends Resourcable { public CompletableFuture dbsizeAsync(); - //------------------------ collectionAsync ------------------------ + //-------------------------- 过期方法 ---------------------------------- + @Deprecated(since = "2.8.0") + public Collection getCollection(final String key, final Type componentType); + + @Deprecated(since = "2.8.0") + public Map> getCollectionMap(final boolean set, final Type componentType, final String... keys); + + @Deprecated(since = "2.8.0") + public int getCollectionSize(final String key); + + @Deprecated(since = "2.8.0") + public Collection getexCollection(final String key, final int expireSeconds, final Type componentType); + + @Deprecated(since = "2.8.0") + public Map> getStringCollectionMap(final boolean set, final String... keys); + + @Deprecated(since = "2.8.0") + public Collection getStringCollection(final String key); + + @Deprecated(since = "2.8.0") + public Collection getexStringCollection(final String key, final int expireSeconds); + + @Deprecated(since = "2.8.0") + public Collection getLongCollection(final String key); + + @Deprecated(since = "2.8.0") + public Map> getLongCollectionMap(final boolean set, final String... keys); + + @Deprecated(since = "2.8.0") + public Collection getexLongCollection(final String key, final int expireSeconds); + @Deprecated(since = "2.8.0") public CompletableFuture> getCollectionAsync(final String key, final Type componentType); @@ -653,7 +652,6 @@ public interface CacheSource extends Resourcable { @Deprecated(since = "2.8.0") public CompletableFuture> getexLongCollectionAsync(final String key, final int expireSeconds); - //-------------------------- 过期方法 ---------------------------------- @Deprecated(since = "2.8.0") default CompletableFuture refreshAsync(final String key, final int expireSeconds) { return expireAsync(key, expireSeconds);