CacheSource增加hstrlen方法

This commit is contained in:
redkale
2023-06-26 08:16:27 +08:00
parent 264dce055c
commit 936f50659b
2 changed files with 24 additions and 0 deletions

View File

@@ -415,6 +415,24 @@ public final class CacheMemorySource extends AbstractCacheSource {
}, getExecutor());
}
@Override
public CompletableFuture<Long> hstrlenAsync(final String key, final String field) {
return supplyAsync(() -> {
if (key == null || field == null) {
return 0L;
}
CacheEntry entry = container.get(key);
if (entry == null || entry.isExpired() || entry.mapValue == null) {
return 0L;
}
Object obj = entry.mapValue.get(field);
if (obj == null) {
return 0L;
}
return (long) obj.toString().length();
}, getExecutor());
}
//----------- hxxx --------------
@Override
public CompletableFuture<Boolean> existsAsync(String key) {

View File

@@ -373,6 +373,10 @@ public interface CacheSource extends Resourcable {
return hsetnx(key, field, Long.class, value);
}
default long hstrlen(String key, String field) {
return hstrlenAsync(key, field).join();
}
default <T> Map<String, T> hgetall(String key, Type type) {
return (Map) hgetallAsync(key, type).join();
}
@@ -1032,6 +1036,8 @@ public interface CacheSource extends Resourcable {
return hsetnxAsync(key, field, Long.class, value);
}
public CompletableFuture<Long> hstrlenAsync(String key, String field);
public <T> CompletableFuture<Map<String, T>> hgetallAsync(String key, Type type);
default CompletableFuture<Map<String, String>> hgetallStringAsync(String key) {