From 63bc4b2d0040d00be95e7b24bff6d9a0af41105d Mon Sep 17 00:00:00 2001 From: Redkale <8730487+redkale@users.noreply.github.com> Date: Sun, 14 Jun 2020 21:52:08 +0800 Subject: [PATCH] =?UTF-8?q?CacheSource=20=E5=A2=9E=E5=8A=A0get=E5=A4=9A?= =?UTF-8?q?=E4=B8=AAkeys=E5=80=BC=E5=BE=97=E7=B3=BB=E5=88=97=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/source/CacheMemorySource.java | 50 ++++++++++++++++--- src/org/redkale/source/CacheSource.java | 12 +++++ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/org/redkale/source/CacheMemorySource.java b/src/org/redkale/source/CacheMemorySource.java index 049cfd6e9..a72e26dd7 100644 --- a/src/org/redkale/source/CacheMemorySource.java +++ b/src/org/redkale/source/CacheMemorySource.java @@ -673,37 +673,31 @@ public class CacheMemorySource extends AbstractService impleme } @Override - public CompletableFuture incrAsync(final String key, long num) { return CompletableFuture.supplyAsync(() -> incr(key, num), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public long decr(final String key) { return incr(key, -1); } @Override - public CompletableFuture decrAsync(final String key) { return CompletableFuture.supplyAsync(() -> decr(key), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public long decr(final String key, long num) { return incr(key, -num); } @Override - public CompletableFuture decrAsync(final String key, long num) { return CompletableFuture.supplyAsync(() -> decr(key, num), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public CompletableFuture removeAsync(final String key) { return CompletableFuture.runAsync(() -> remove(key), getExecutor()).whenComplete(futureCompleteConsumer); } @@ -743,6 +737,50 @@ public class CacheMemorySource extends AbstractService impleme return map; } + @Override + public Map getLongMap(final String... keys) { + Map map = new LinkedHashMap<>(); + for (String key : keys) { + Number n = (Number) get(key); + map.put(key, n == null ? null : n.longValue()); + } + return map; + } + + @Override + public CompletableFuture> getLongMapAsync(final String... keys) { + return CompletableFuture.supplyAsync(() -> getLongMap(keys), getExecutor()); + } + + @Override + public Map getStringMap(final String... keys) { + Map map = new LinkedHashMap<>(); + for (String key : keys) { + Object n = get(key); + map.put(key, n == null ? null : n.toString()); + } + return map; + } + + @Override + public CompletableFuture> getStringMapAsync(final String... keys) { + return CompletableFuture.supplyAsync(() -> getStringMap(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)); + } + 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); diff --git a/src/org/redkale/source/CacheSource.java b/src/org/redkale/source/CacheSource.java index 5b25179bb..325f51d0b 100644 --- a/src/org/redkale/source/CacheSource.java +++ b/src/org/redkale/source/CacheSource.java @@ -99,6 +99,8 @@ public interface CacheSource { public long decr(final String key, long num); + public Map getMap(final Type componentType, final String... keys); + public Collection getCollection(final String key); public Collection getCollection(final String key, final Type componentType); @@ -149,6 +151,8 @@ public interface CacheSource { public void setString(final int expireSeconds, final String key, final String value); + public Map getStringMap(final String... keys); + public Collection getStringCollection(final String key); public Map> getStringCollectionMap(final boolean set, final String... keys); @@ -173,6 +177,8 @@ public interface CacheSource { public void setLong(final int expireSeconds, final String key, final long value); + public Map getLongMap(final String... keys); + public Collection getLongCollection(final String key); public Map> getLongCollectionMap(final boolean set, final String... keys); @@ -256,6 +262,8 @@ public interface CacheSource { public CompletableFuture decrAsync(final String key, long num); + public CompletableFuture> getMapAsync(final Type componentType, final String... keys); + public CompletableFuture> getCollectionAsync(final String key); public CompletableFuture> getCollectionAsync(final String key, final Type componentType); @@ -306,6 +314,8 @@ public interface CacheSource { public CompletableFuture setStringAsync(final int expireSeconds, final String key, final String value); + public CompletableFuture> getStringMapAsync(final String... keys); + public CompletableFuture> getStringCollectionAsync(final String key); public CompletableFuture>> getStringCollectionMapAsync(final boolean set, final String... keys); @@ -330,6 +340,8 @@ public interface CacheSource { public CompletableFuture setLongAsync(final int expireSeconds, final String key, final long value); + public CompletableFuture> getLongMapAsync(final String... keys); + public CompletableFuture> getLongCollectionAsync(final String key); public CompletableFuture>> getLongCollectionMapAsync(final boolean set, final String... keys);