优化CacheSource
This commit is contained in:
@@ -991,6 +991,65 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
|||||||
return CompletableFuture.supplyAsync(() -> getLongArray(keys), getExecutor());
|
return CompletableFuture.supplyAsync(() -> getLongArray(keys), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> Map<String, T> mget(final Type componentType, final String... keys) {
|
||||||
|
Map<String, T> map = new LinkedHashMap<>();
|
||||||
|
for (String key : keys) {
|
||||||
|
map.put(key, (T) get(key, componentType));
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> mgetString(final String... keys) {
|
||||||
|
Map<String, String> 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 Map<String, Long> mgetLong(final String... keys) {
|
||||||
|
Map<String, Long> 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 Map<String, byte[]> mgetBytes(final String... keys) {
|
||||||
|
Map<String, byte[]> map = new LinkedHashMap<>();
|
||||||
|
for (String key : keys) {
|
||||||
|
byte[] n = get(key, byte[].class);
|
||||||
|
map.put(key, get(key, byte[].class));
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> CompletableFuture<Map<String, T>> mgetAsync(final Type componentType, final String... keys) {
|
||||||
|
return CompletableFuture.completedFuture(mget(componentType, keys));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Map<String, String>> mgetStringAsync(final String... keys) {
|
||||||
|
return CompletableFuture.completedFuture(mgetString(keys));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Map<String, Long>> mgetLongAsync(final String... keys) {
|
||||||
|
return CompletableFuture.completedFuture(mgetLong(keys));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Map<String, byte[]>> mgetBytesAsync(final String... keys) {
|
||||||
|
return CompletableFuture.completedFuture(mgetBytes(keys));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getStringMap(final String... keys) {
|
public Map<String, String> getStringMap(final String... keys) {
|
||||||
Map<String, String> map = new LinkedHashMap<>();
|
Map<String, String> map = new LinkedHashMap<>();
|
||||||
|
|||||||
@@ -43,6 +43,15 @@ public interface CacheSource extends Resourcable {
|
|||||||
|
|
||||||
public byte[] getBytes(final String key);
|
public byte[] getBytes(final String key);
|
||||||
|
|
||||||
|
//------------------------ mget ------------------------
|
||||||
|
public <T> Map<String, T> mget(final Type componentType, final String... keys);
|
||||||
|
|
||||||
|
public Map<String, String> mgetString(final String... keys);
|
||||||
|
|
||||||
|
public Map<String, Long> mgetLong(final String... keys);
|
||||||
|
|
||||||
|
public Map<String, byte[]> mgetBytes(final String... keys);
|
||||||
|
|
||||||
//------------------------ getex ------------------------
|
//------------------------ getex ------------------------
|
||||||
public <T> T getex(final String key, final int expireSeconds, final Type type);
|
public <T> T getex(final String key, final int expireSeconds, final Type type);
|
||||||
|
|
||||||
@@ -190,6 +199,10 @@ public interface CacheSource extends Resourcable {
|
|||||||
public <T> int lrem(final String key, final Type componentType, final T value);
|
public <T> int lrem(final String key, final Type componentType, final T value);
|
||||||
|
|
||||||
//---------- list-string ----------
|
//---------- list-string ----------
|
||||||
|
default List<String> lrangeString(final String key) {
|
||||||
|
return lrange(key, String.class);
|
||||||
|
}
|
||||||
|
|
||||||
public void rpushString(final String key, final String value);
|
public void rpushString(final String key, final String value);
|
||||||
|
|
||||||
public int lremString(final String key, final String value);
|
public int lremString(final String key, final String value);
|
||||||
@@ -217,6 +230,10 @@ public interface CacheSource extends Resourcable {
|
|||||||
public <T> Set<T> spop(final String key, final int count, final Type componentType);
|
public <T> Set<T> spop(final String key, final int count, final Type componentType);
|
||||||
|
|
||||||
//---------- set-string ----------
|
//---------- set-string ----------
|
||||||
|
default Set<String> smembersString(final String key) {
|
||||||
|
return smembers(key, String.class);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean sismemberString(final String key, final String value);
|
public boolean sismemberString(final String key, final String value);
|
||||||
|
|
||||||
public void saddString(final String key, final String value);
|
public void saddString(final String key, final String value);
|
||||||
@@ -251,14 +268,8 @@ public interface CacheSource extends Resourcable {
|
|||||||
|
|
||||||
public int getKeySize();
|
public int getKeySize();
|
||||||
|
|
||||||
public <T> Map<String, T> getMap(final Type componentType, final String... keys);
|
|
||||||
|
|
||||||
public Map<String, String> getStringMap(final String... keys);
|
|
||||||
|
|
||||||
public String[] getStringArray(final String... keys);
|
public String[] getStringArray(final String... keys);
|
||||||
|
|
||||||
public Map<String, Long> getLongMap(final String... keys);
|
|
||||||
|
|
||||||
public Long[] getLongArray(final String... keys);
|
public Long[] getLongArray(final String... keys);
|
||||||
|
|
||||||
//------------------------ collection ------------------------
|
//------------------------ collection ------------------------
|
||||||
@@ -306,6 +317,15 @@ public interface CacheSource extends Resourcable {
|
|||||||
|
|
||||||
public CompletableFuture<byte[]> getBytesAsync(final String key);
|
public CompletableFuture<byte[]> getBytesAsync(final String key);
|
||||||
|
|
||||||
|
//------------------------ mgetAsync ------------------------
|
||||||
|
public <T> CompletableFuture<Map<String, T>> mgetAsync(final Type componentType, final String... keys);
|
||||||
|
|
||||||
|
public CompletableFuture<Map<String, String>> mgetStringAsync(final String... keys);
|
||||||
|
|
||||||
|
public CompletableFuture<Map<String, Long>> mgetLongAsync(final String... keys);
|
||||||
|
|
||||||
|
public CompletableFuture<Map<String, byte[]>> mgetBytesAsync(final String... keys);
|
||||||
|
|
||||||
//------------------------ getexAsync ------------------------
|
//------------------------ getexAsync ------------------------
|
||||||
public <T> CompletableFuture<T> getexAsync(final String key, final int expireSeconds, final Type type);
|
public <T> CompletableFuture<T> getexAsync(final String key, final int expireSeconds, final Type type);
|
||||||
|
|
||||||
@@ -480,6 +500,10 @@ public interface CacheSource extends Resourcable {
|
|||||||
public <T> CompletableFuture<Set<T>> spopAsync(final String key, final int count, final Type componentType);
|
public <T> CompletableFuture<Set<T>> spopAsync(final String key, final int count, final Type componentType);
|
||||||
|
|
||||||
//---------- set-string ----------
|
//---------- set-string ----------
|
||||||
|
default CompletableFuture<Set<String>> smembersStringAsync(final String key) {
|
||||||
|
return smembersAsync(key, String.class);
|
||||||
|
}
|
||||||
|
|
||||||
public CompletableFuture<Boolean> sismemberStringAsync(final String key, final String value);
|
public CompletableFuture<Boolean> sismemberStringAsync(final String key, final String value);
|
||||||
|
|
||||||
public CompletableFuture<Void> saddStringAsync(final String key, final String value);
|
public CompletableFuture<Void> saddStringAsync(final String key, final String value);
|
||||||
@@ -512,16 +536,10 @@ public interface CacheSource extends Resourcable {
|
|||||||
|
|
||||||
public CompletableFuture<List<String>> keysAsync(String pattern);
|
public CompletableFuture<List<String>> keysAsync(String pattern);
|
||||||
|
|
||||||
public <T> CompletableFuture<Map<String, T>> getMapAsync(final Type componentType, final String... keys);
|
|
||||||
|
|
||||||
public CompletableFuture<Integer> getKeySizeAsync();
|
public CompletableFuture<Integer> getKeySizeAsync();
|
||||||
|
|
||||||
public CompletableFuture<Map<String, String>> getStringMapAsync(final String... keys);
|
|
||||||
|
|
||||||
public CompletableFuture<String[]> getStringArrayAsync(final String... keys);
|
public CompletableFuture<String[]> getStringArrayAsync(final String... keys);
|
||||||
|
|
||||||
public CompletableFuture<Map<String, Long>> getLongMapAsync(final String... keys);
|
|
||||||
|
|
||||||
public CompletableFuture<Long[]> getLongArrayAsync(final String... keys);
|
public CompletableFuture<Long[]> getLongArrayAsync(final String... keys);
|
||||||
|
|
||||||
//------------------------ collectionAsync ------------------------
|
//------------------------ collectionAsync ------------------------
|
||||||
@@ -930,4 +948,34 @@ public interface CacheSource extends Resourcable {
|
|||||||
default CompletableFuture<List<String>> queryKeysEndsWithAsync(String endsWith) {
|
default CompletableFuture<List<String>> queryKeysEndsWithAsync(String endsWith) {
|
||||||
return keysAsync("*" + endsWith);
|
return keysAsync("*" + endsWith);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
default <T> Map<String, T> getMap(final Type componentType, final String... keys) {
|
||||||
|
return mget(componentType, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
default Map<String, String> getStringMap(final String... keys) {
|
||||||
|
return mgetString(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
default Map<String, Long> getLongMap(final String... keys) {
|
||||||
|
return mgetLong(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
default <T> CompletableFuture<Map<String, T>> getMapAsync(final Type componentType, final String... keys) {
|
||||||
|
return mgetAsync(componentType, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
default CompletableFuture<Map<String, String>> getStringMapAsync(final String... keys) {
|
||||||
|
return mgetStringAsync(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
default CompletableFuture<Map<String, Long>> getLongMapAsync(final String... keys) {
|
||||||
|
return mgetLongAsync(keys);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -748,7 +748,10 @@ public final class ResourceFactory {
|
|||||||
String presname = res1 == null ? (res2 == null ? srcResourceName : res2.name()) : res1.name();
|
String presname = res1 == null ? (res2 == null ? srcResourceName : res2.name()) : res1.name();
|
||||||
if (presname == null) {
|
if (presname == null) {
|
||||||
if (srcObj instanceof Resourcable) {
|
if (srcObj instanceof Resourcable) {
|
||||||
tname = tname.replace(RESOURCE_PARENT_NAME, ((Resourcable) srcObj).resourceName());
|
String oname = ((Resourcable) srcObj).resourceName();
|
||||||
|
if (oname != null) {
|
||||||
|
tname = tname.replace(RESOURCE_PARENT_NAME, oname);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.log(Level.SEVERE, srcObj.getClass().getName() + " not found @Resource on Class or not implements Resourcable");
|
logger.log(Level.SEVERE, srcObj.getClass().getName() + " not found @Resource on Class or not implements Resourcable");
|
||||||
}
|
}
|
||||||
@@ -813,7 +816,7 @@ public final class ResourceFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rs == null && re == null && autoRegNull) {
|
if (rs == null && re == null && autoRegNull && rcname.indexOf('$') < 0) {
|
||||||
register(rcname, gencType, null); //自动注入null的值
|
register(rcname, gencType, null); //自动注入null的值
|
||||||
re = findEntry(rcname, gencType);
|
re = findEntry(rcname, gencType);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user