diff --git a/src/main/java/org/redkale/source/CacheMemorySource.java b/src/main/java/org/redkale/source/CacheMemorySource.java index 442a32312..8e7359863 100644 --- a/src/main/java/org/redkale/source/CacheMemorySource.java +++ b/src/main/java/org/redkale/source/CacheMemorySource.java @@ -923,6 +923,11 @@ public final class CacheMemorySource extends AbstractCacheSource { return (Set) get(key, componentType); } + @Override + public List lrange(final String key, final Type componentType) { + return (List) get(key, componentType); + } + @Override public Map> smembers(final Type componentType, final String... keys) { Map> map = new HashMap<>(); @@ -933,6 +938,16 @@ public final class CacheMemorySource extends AbstractCacheSource { return map; } + @Override + public Map> lrange(final Type componentType, final String... keys) { + Map> map = new HashMap<>(); + for (String key : keys) { + List s = (List) get(key, componentType); + if (s != null) map.put(key, s); + } + return map; + } + @Override public Map> getCollectionMap(final boolean set, final Type componentType, final String... keys) { Map> map = new HashMap<>(); @@ -1049,6 +1064,11 @@ public final class CacheMemorySource extends AbstractCacheSource { return map; } + @Override + public CompletableFuture>> lrangeAsync(Type componentType, String... keys) { + return CompletableFuture.supplyAsync(() -> lrange(componentType, keys), getExecutor()); + } + @Override public CompletableFuture>> smembersAsync(Type componentType, String... keys) { return CompletableFuture.supplyAsync(() -> smembers(componentType, keys), getExecutor()); @@ -1089,6 +1109,11 @@ public final class CacheMemorySource extends AbstractCacheSource { return CompletableFuture.supplyAsync(() -> smembers(key, componentType), getExecutor()); } + @Override + public CompletableFuture> lrangeAsync(String key, Type componentType) { + return CompletableFuture.supplyAsync(() -> lrange(key, componentType), getExecutor()); + } + @Override public int getCollectionSize(final String key) { Collection collection = (Collection) get(key, Object.class); @@ -1122,25 +1147,25 @@ public final class CacheMemorySource extends AbstractCacheSource { } @Override - public boolean existsStringSetItem(final String key, final String value) { + public boolean sismemberString(final String key, final String value) { Collection list = getStringCollection(key); return list != null && list.contains(value); } @Override - public CompletableFuture existsStringSetItemAsync(final String key, final String value) { - return CompletableFuture.supplyAsync(() -> existsStringSetItem(key, value), getExecutor()); + public CompletableFuture sismemberStringAsync(final String key, final String value) { + return CompletableFuture.supplyAsync(() -> sismemberString(key, value), getExecutor()); } @Override - public boolean existsLongSetItem(final String key, final long value) { + public boolean sismemberLong(final String key, final long value) { Collection list = getLongCollection(key); return list != null && list.contains(value); } @Override - public CompletableFuture existsLongSetItemAsync(final String key, final long value) { - return CompletableFuture.supplyAsync(() -> existsLongSetItem(key, value), getExecutor()); + public CompletableFuture sismemberLongAsync(final String key, final long value) { + return CompletableFuture.supplyAsync(() -> sismemberLong(key, value), getExecutor()); } @Override @@ -1178,37 +1203,37 @@ public final class CacheMemorySource extends AbstractCacheSource { } @Override - public void appendListItem(String key, Type componentType, T value) { + public void rpush(String key, Type componentType, T value) { appendListItem(CacheEntryType.OBJECT_LIST, key, value); } @Override - public void appendStringListItem(String key, String value) { + public void rpushString(String key, String value) { appendListItem(CacheEntryType.STRING_LIST, key, value); } @Override - public void appendLongListItem(String key, long value) { + public void rpushLong(String key, long value) { appendListItem(CacheEntryType.LONG_LIST, key, value); } @Override - public CompletableFuture appendListItemAsync(final String key, final Type componentType, final T value) { - return CompletableFuture.runAsync(() -> appendListItem(key, componentType, value), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture rpushAsync(final String key, final Type componentType, final T value) { + return CompletableFuture.runAsync(() -> rpush(key, componentType, value), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public CompletableFuture appendStringListItemAsync(final String key, final String value) { - return CompletableFuture.runAsync(() -> appendStringListItem(key, value), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture rpushStringAsync(final String key, final String value) { + return CompletableFuture.runAsync(() -> rpushString(key, value), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public CompletableFuture appendLongListItemAsync(final String key, final long value) { - return CompletableFuture.runAsync(() -> appendLongListItem(key, value), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture rpushLongAsync(final String key, final long value) { + return CompletableFuture.runAsync(() -> rpushLong(key, value), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public int removeListItem(String key, final Type componentType, T value) { + public int lrem(String key, final Type componentType, T value) { if (key == null) return 0; CacheEntry entry = container.get(key); if (entry == null || entry.listValue == null) return 0; @@ -1216,7 +1241,7 @@ public final class CacheMemorySource extends AbstractCacheSource { } @Override - public int removeStringListItem(String key, String value) { + public int lremString(String key, String value) { if (key == null) return 0; CacheEntry entry = container.get(key); if (entry == null || entry.listValue == null) return 0; @@ -1224,7 +1249,7 @@ public final class CacheMemorySource extends AbstractCacheSource { } @Override - public int removeLongListItem(String key, long value) { + public int lremLong(String key, long value) { if (key == null) return 0; CacheEntry entry = container.get(key); if (entry == null || entry.listValue == null) return 0; @@ -1232,37 +1257,37 @@ public final class CacheMemorySource extends AbstractCacheSource { } @Override - public CompletableFuture removeListItemAsync(final String key, final Type componentType, T value) { - return CompletableFuture.supplyAsync(() -> removeListItem(key, componentType, value), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture lremAsync(final String key, final Type componentType, T value) { + return CompletableFuture.supplyAsync(() -> lrem(key, componentType, value), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public CompletableFuture removeStringListItemAsync(final String key, final String value) { - return CompletableFuture.supplyAsync(() -> removeStringListItem(key, value), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture lremStringAsync(final String key, final String value) { + return CompletableFuture.supplyAsync(() -> lremString(key, value), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public CompletableFuture removeLongListItemAsync(final String key, final long value) { - return CompletableFuture.supplyAsync(() -> removeLongListItem(key, value), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture lremLongAsync(final String key, final long value) { + return CompletableFuture.supplyAsync(() -> lremLong(key, value), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public String spopStringSetItem(final String key) { + public String spopString(final String key) { return (String) spop(key, String.class); } @Override - public Set spopStringSetItem(final String key, int count) { + public Set spopString(final String key, int count) { return spop(key, count, String.class); } @Override - public Long spopLongSetItem(final String key) { + public Long spopLong(final String key) { return (Long) spop(key, long.class); } @Override - public Set spopLongSetItem(final String key, int count) { + public Set spopLong(final String key, int count) { return spop(key, count, long.class); } @@ -1325,12 +1350,12 @@ public final class CacheMemorySource extends AbstractCacheSource { } @Override - public void appendStringSetItem(String key, String value) { + public void saddString(String key, String value) { appendSetItem(CacheEntryType.OBJECT_SET, key, value); } @Override - public void appendLongSetItem(String key, long value) { + public void saddLong(String key, long value) { appendSetItem(CacheEntryType.OBJECT_SET, key, value); } @@ -1340,13 +1365,13 @@ public final class CacheMemorySource extends AbstractCacheSource { } @Override - public CompletableFuture appendStringSetItemAsync(final String key, final String value) { - return CompletableFuture.runAsync(() -> appendStringSetItem(key, value), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture saddStringAsync(final String key, final String value) { + return CompletableFuture.runAsync(() -> saddString(key, value), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public CompletableFuture appendLongSetItemAsync(final String key, final long value) { - return CompletableFuture.runAsync(() -> appendLongSetItem(key, value), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture saddLongAsync(final String key, final long value) { + return CompletableFuture.runAsync(() -> saddLong(key, value), getExecutor()).whenComplete(futureCompleteConsumer); } @Override @@ -1358,7 +1383,7 @@ public final class CacheMemorySource extends AbstractCacheSource { } @Override - public int removeStringSetItem(String key, String value) { + public int sremString(String key, String value) { if (key == null) return 0; CacheEntry entry = container.get(key); if (entry == null || entry.csetValue == null) return 0; @@ -1366,7 +1391,7 @@ public final class CacheMemorySource extends AbstractCacheSource { } @Override - public int removeLongSetItem(String key, long value) { + public int sremLong(String key, long value) { if (key == null) return 0; CacheEntry entry = container.get(key); if (entry == null || entry.csetValue == null) return 0; @@ -1379,13 +1404,13 @@ public final class CacheMemorySource extends AbstractCacheSource { } @Override - public CompletableFuture removeStringSetItemAsync(final String key, final String value) { - return CompletableFuture.supplyAsync(() -> removeStringSetItem(key, value), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture sremStringAsync(final String key, final String value) { + return CompletableFuture.supplyAsync(() -> sremString(key, value), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public CompletableFuture removeLongSetItemAsync(final String key, final long value) { - return CompletableFuture.supplyAsync(() -> removeLongSetItem(key, value), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture sremLongAsync(final String key, final long value) { + return CompletableFuture.supplyAsync(() -> sremLong(key, value), getExecutor()).whenComplete(futureCompleteConsumer); } @Override @@ -1525,23 +1550,23 @@ public final class CacheMemorySource extends AbstractCacheSource { } @Override - public CompletableFuture spopStringSetItemAsync(String key) { - return CompletableFuture.supplyAsync(() -> spopStringSetItem(key), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture spopStringAsync(String key) { + return CompletableFuture.supplyAsync(() -> spopString(key), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public CompletableFuture> spopStringSetItemAsync(String key, int count) { - return CompletableFuture.supplyAsync(() -> spopStringSetItem(key, count), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture> spopStringAsync(String key, int count) { + return CompletableFuture.supplyAsync(() -> spopString(key, count), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public CompletableFuture spopLongSetItemAsync(String key) { - return CompletableFuture.supplyAsync(() -> spopLongSetItem(key), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture spopLongAsync(String key) { + return CompletableFuture.supplyAsync(() -> spopLong(key), getExecutor()).whenComplete(futureCompleteConsumer); } @Override - public CompletableFuture> spopLongSetItemAsync(String key, int count) { - return CompletableFuture.supplyAsync(() -> spopLongSetItem(key, count), getExecutor()).whenComplete(futureCompleteConsumer); + public CompletableFuture> spopLongAsync(String key, int count) { + return CompletableFuture.supplyAsync(() -> spopLong(key, count), getExecutor()).whenComplete(futureCompleteConsumer); } public static enum CacheEntryType { diff --git a/src/main/java/org/redkale/source/CacheSource.java b/src/main/java/org/redkale/source/CacheSource.java index 7daa9131c..f1499cd9c 100644 --- a/src/main/java/org/redkale/source/CacheSource.java +++ b/src/main/java/org/redkale/source/CacheSource.java @@ -175,17 +175,23 @@ public interface CacheSource extends Resourcable { public Map hmap(final String key, final Type type, int offset, int limit, String pattern); //------------------------ list ------------------------ - public void appendListItem(final String key, final Type componentType, final T value); + public List lrange(final String key, final Type componentType); - public int removeListItem(final String key, final Type componentType, final T value); + public Map> lrange(final Type componentType, final String... keys); - public void appendStringListItem(final String key, final String value); + public void rpush(final String key, final Type componentType, final T value); - public int removeStringListItem(final String key, final String value); + public int lrem(final String key, final Type componentType, final T value); - public void appendLongListItem(final String key, final long value); + //---------- list-string ---------- + public void rpushString(final String key, final String value); - public int removeLongListItem(final String key, final long value); + public int lremString(final String key, final String value); + + //---------- list-long ---------- + public void rpushLong(final String key, final long value); + + public int lremLong(final String key, final long value); //------------------------ set ------------------------ public Set smembers(final String key, final Type componentType); @@ -203,26 +209,26 @@ public interface CacheSource extends Resourcable { public Set spop(final String key, final int count, final Type componentType); //---------- set-string ---------- - public boolean existsStringSetItem(final String key, final String value); + public boolean sismemberString(final String key, final String value); - public void appendStringSetItem(final String key, final String value); + public void saddString(final String key, final String value); - public int removeStringSetItem(final String key, final String value); + public int sremString(final String key, final String value); - public String spopStringSetItem(final String key); + public String spopString(final String key); - public Set spopStringSetItem(final String key, final int count); + public Set spopString(final String key, final int count); //---------- set-long ---------- - public boolean existsLongSetItem(final String key, final long value); + public boolean sismemberLong(final String key, final long value); - public void appendLongSetItem(final String key, final long value); + public void saddLong(final String key, final long value); - public int removeLongSetItem(final String key, final long value); + public int sremLong(final String key, final long value); - public Long spopLongSetItem(final String key); + public Long spopLong(final String key); - public Set spopLongSetItem(final String key, final int count); + public Set spopLong(final String key, final int count); //------------------------ collection ------------------------ @Deprecated @@ -419,18 +425,24 @@ public interface CacheSource extends Resourcable { public CompletableFuture> hmapAsync(final String key, final Type type, int offset, int limit, String pattern); - //------------------------ listAsync ------------------------ - public CompletableFuture appendListItemAsync(final String key, final Type componentType, final T value); + //------------------------ listAsync ------------------------ + public CompletableFuture> lrangeAsync(final String key, final Type componentType); - public CompletableFuture removeListItemAsync(final String key, final Type componentType, final T value); + public CompletableFuture>> lrangeAsync(final Type componentType, final String... keys); - public CompletableFuture appendStringListItemAsync(final String key, final String value); + public CompletableFuture rpushAsync(final String key, final Type componentType, final T value); - public CompletableFuture removeStringListItemAsync(final String key, final String value); + public CompletableFuture lremAsync(final String key, final Type componentType, final T value); - public CompletableFuture appendLongListItemAsync(final String key, final long value); + //---------- list-string ---------- + public CompletableFuture rpushStringAsync(final String key, final String value); - public CompletableFuture removeLongListItemAsync(final String key, final long value); + public CompletableFuture lremStringAsync(final String key, final String value); + + //---------- list-long ---------- + public CompletableFuture rpushLongAsync(final String key, final long value); + + public CompletableFuture lremLongAsync(final String key, final long value); //------------------------ setAsync ------------------------ public CompletableFuture> smembersAsync(final String key, final Type componentType); @@ -448,26 +460,26 @@ public interface CacheSource extends Resourcable { public CompletableFuture> spopAsync(final String key, final int count, final Type componentType); //---------- set-string ---------- - public CompletableFuture existsStringSetItemAsync(final String key, final String value); + public CompletableFuture sismemberStringAsync(final String key, final String value); - public CompletableFuture appendStringSetItemAsync(final String key, final String value); + public CompletableFuture saddStringAsync(final String key, final String value); - public CompletableFuture removeStringSetItemAsync(final String key, final String value); + public CompletableFuture sremStringAsync(final String key, final String value); - public CompletableFuture spopStringSetItemAsync(final String key); + public CompletableFuture spopStringAsync(final String key); - public CompletableFuture> spopStringSetItemAsync(final String key, final int count); + public CompletableFuture> spopStringAsync(final String key, final int count); //---------- set-long ---------- - public CompletableFuture existsLongSetItemAsync(final String key, final long value); + public CompletableFuture sismemberLongAsync(final String key, final long value); - public CompletableFuture appendLongSetItemAsync(final String key, final long value); + public CompletableFuture saddLongAsync(final String key, final long value); - public CompletableFuture removeLongSetItemAsync(final String key, final long value); + public CompletableFuture sremLongAsync(final String key, final long value); - public CompletableFuture spopLongSetItemAsync(final String key); + public CompletableFuture spopLongAsync(final String key); - public CompletableFuture> spopLongSetItemAsync(final String key, final int count); + public CompletableFuture> spopLongAsync(final String key, final int count); //------------------------ collectionAsync ------------------------ @Deprecated @@ -704,4 +716,164 @@ public interface CacheSource extends Resourcable { default CompletableFuture> spopSetItemAsync(final String key, final int count, final Type componentType) { return spopAsync(key, count, componentType); } + + @Deprecated + default boolean existsStringSetItem(final String key, final String value) { + return sismemberString(key, value); + } + + @Deprecated + default void appendStringSetItem(final String key, final String value) { + saddString(key, value); + } + + @Deprecated + default int removeStringSetItem(final String key, final String value) { + return sremString(key, value); + } + + @Deprecated + default String spopStringSetItem(final String key) { + return spopString(key); + } + + @Deprecated + default Set spopStringSetItem(final String key, final int count) { + return spopString(key, count); + } + + @Deprecated + default boolean existsLongSetItem(final String key, final long value) { + return sismemberLong(key, value); + } + + @Deprecated + default void appendLongSetItem(final String key, final long value) { + saddLong(key, value); + } + + @Deprecated + default int removeLongSetItem(final String key, final long value) { + return sremLong(key, value); + } + + @Deprecated + default Long spopLongSetItem(final String key) { + return spopLong(key); + } + + @Deprecated + default Set spopLongSetItem(final String key, final int count) { + return spopLong(key, count); + } + + @Deprecated + default CompletableFuture existsStringSetItemAsync(final String key, final String value) { + return sismemberStringAsync(key, value); + } + + @Deprecated + default CompletableFuture appendStringSetItemAsync(final String key, final String value) { + return saddStringAsync(key, value); + } + + @Deprecated + default CompletableFuture removeStringSetItemAsync(final String key, final String value) { + return sremStringAsync(key, value); + } + + @Deprecated + default CompletableFuture spopStringSetItemAsync(final String key) { + return spopStringAsync(key); + } + + @Deprecated + default CompletableFuture> spopStringSetItemAsync(final String key, final int count) { + return spopStringAsync(key, count); + } + + @Deprecated + default CompletableFuture existsLongSetItemAsync(final String key, final long value) { + return sismemberLongAsync(key, value); + } + + @Deprecated + default CompletableFuture appendLongSetItemAsync(final String key, final long value) { + return saddLongAsync(key, value); + } + + @Deprecated + default CompletableFuture removeLongSetItemAsync(final String key, final long value) { + return sremLongAsync(key, value); + } + + @Deprecated + default CompletableFuture spopLongSetItemAsync(final String key) { + return spopLongAsync(key); + } + + @Deprecated + default CompletableFuture> spopLongSetItemAsync(final String key, final int count) { + return spopLongAsync(key, count); + } + + @Deprecated + default CompletableFuture appendListItemAsync(final String key, final Type componentType, final T value) { + return rpushAsync(key, componentType, value); + } + + @Deprecated + default CompletableFuture removeListItemAsync(final String key, final Type componentType, final T value) { + return lremAsync(key, componentType, value); + } + + @Deprecated + default CompletableFuture appendStringListItemAsync(final String key, final String value) { + return rpushStringAsync(key, value); + } + + @Deprecated + default CompletableFuture removeStringListItemAsync(final String key, final String value) { + return lremStringAsync(key, value); + } + + @Deprecated + default CompletableFuture appendLongListItemAsync(final String key, final long value) { + return rpushLongAsync(key, value); + } + + @Deprecated + default CompletableFuture removeLongListItemAsync(final String key, final long value) { + return lremLongAsync(key, value); + } + + @Deprecated + default void appendListItem(final String key, final Type componentType, final T value) { + rpush(key, componentType, value); + } + + @Deprecated + default int removeListItem(final String key, final Type componentType, final T value) { + return lrem(key, componentType, value); + } + + @Deprecated + default void appendStringListItem(final String key, final String value) { + rpushString(key, value); + } + + @Deprecated + default int removeStringListItem(final String key, final String value) { + return lremString(key, value); + } + + @Deprecated + default void appendLongListItem(final String key, final long value) { + rpushLong(key, value); + } + + @Deprecated + default int removeLongListItem(final String key, final long value) { + return lremLong(key, value); + } }