同步:redkale 升级
This commit is contained in:
@@ -145,6 +145,8 @@ public class MyRedisCacheSource extends RedisCacheSource {
|
||||
* */
|
||||
|
||||
// --------------------
|
||||
/*
|
||||
supper had support
|
||||
public <N extends Number> void zadd(String key, Map<Serializable, N> kv) {
|
||||
if (kv == null || kv.isEmpty()) {
|
||||
return;
|
||||
@@ -155,16 +157,17 @@ public class MyRedisCacheSource extends RedisCacheSource {
|
||||
args.add(v);
|
||||
});
|
||||
|
||||
sendAsync("ZADD", key, args.toArray(Serializable[]::new)).join();
|
||||
sendAsync(RedisCommand.ZADD, key, args.toArray(Serializable[]::new)).join();
|
||||
}
|
||||
|
||||
public <N extends Number> double zincr(String key, Serializable number, N n) {
|
||||
return sendAsync("ZINCRBY", key, number, n).thenApply(x -> x.getDoubleValue(0d)).join();
|
||||
return sendAsync(RedisCommand.ZINCRBY, key, number, n).thenApply(x -> x.getDoubleValue(0d)).join();
|
||||
}
|
||||
|
||||
public void zrem(String key, Serializable... vs) {
|
||||
sendAsync("ZREM", key, vs).join();
|
||||
}
|
||||
@Override
|
||||
public long zrem(String key, String... vs) {
|
||||
return sendAsync(RedisCommand.ZREM, key, keysArgs(key, vs)).thenApply(x -> x.getLongValue(0L)).join();
|
||||
}*/
|
||||
|
||||
/*public <T> List<T> zexists(String key, T... fields) {
|
||||
if (fields == null || fields.length == 0) {
|
||||
@@ -196,27 +199,27 @@ public class MyRedisCacheSource extends RedisCacheSource {
|
||||
|
||||
//--------------------- bit ------------------------------
|
||||
public boolean getBit(String key, int offset) {
|
||||
return sendAsync("GETBIT", key, key.getBytes(StandardCharsets.UTF_8), String.valueOf(offset).getBytes(StandardCharsets.UTF_8)).thenApply(v -> v.getIntValue(0) > 0).join();
|
||||
return sendAsync(RedisCommand.GETBIT, key, key.getBytes(StandardCharsets.UTF_8), String.valueOf(offset).getBytes(StandardCharsets.UTF_8)).thenApply(v -> v.getIntValue(0) > 0).join();
|
||||
}
|
||||
|
||||
public void setBit(String key, int offset, boolean bool) {
|
||||
sendAsync("SETBIT", key, offset, bool ? 1 : 0).join();
|
||||
sendAsync(RedisCommand.SETBIT, key, keysArgs(key, offset + "", bool ? "1" : "0")).join();
|
||||
}
|
||||
//--------------------- bit ------------------------------
|
||||
|
||||
//--------------------- lock ------------------------------
|
||||
// 尝试加锁,成功返回0,否则返回上一锁剩余毫秒值
|
||||
public long tryLock(String key, int millis) {
|
||||
Serializable[] obj = {"" +
|
||||
String[] obj = {"" +
|
||||
"if (redis.call('EXISTS',KEYS[1]) == 0) then " +
|
||||
"redis.call('PSETEX',KEYS[1],ARGV[1],1); " +
|
||||
"return 0; " +
|
||||
"else " +
|
||||
"return redis.call('PTTL',KEYS[1]); " +
|
||||
"end;", 1, key, millis
|
||||
"end;", 1 + "", key, millis + ""
|
||||
};
|
||||
|
||||
return sendAsync("EVAL", null, obj).thenApply(v -> v.getIntValue(1)).join();
|
||||
return sendAsync(RedisCommand.EVAL, null, keysArgs(null, obj)).thenApply(v -> v.getIntValue(1)).join();
|
||||
}
|
||||
|
||||
// 加锁
|
||||
@@ -244,29 +247,33 @@ public class MyRedisCacheSource extends RedisCacheSource {
|
||||
}
|
||||
|
||||
public void set(String key, Serializable value) {
|
||||
sendAsync("SET", key, value).join();
|
||||
sendAsync(RedisCommand.SET, key, keysArgs(key, value + "")).join();
|
||||
}
|
||||
|
||||
//--------------------- set ------------------------------
|
||||
public <T> void sadd(String key, Collection<T> args) {
|
||||
saddAsync(key, args.toArray(Serializable[]::new)).join();
|
||||
/*public <T> void sadd(String key, Collection<T> args) {
|
||||
saddAsync(key, args.toArray(T[]::new)).join();
|
||||
}*/
|
||||
|
||||
/*public void sadd(String key, Serializable... args) {
|
||||
String[] arr = new String[args.length];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
arr[i] = args[i] + "";
|
||||
}
|
||||
saddAsync(key, arr).join();
|
||||
}
|
||||
|
||||
public void sadd(String key, Serializable... args) {
|
||||
saddAsync(key, Arrays.stream(args).toArray(Serializable[]::new)).join();
|
||||
}
|
||||
|
||||
public void srem(String key, Serializable... args) {
|
||||
public void srem(String key, String... args) {
|
||||
sremAsync(key, args).join();
|
||||
}
|
||||
|
||||
public CompletableFuture<RedisCacheResult> saddAsync(String key, Serializable... args) {
|
||||
return sendAsync("SADD", key, args);
|
||||
return sendAsync(RedisCommand.SADD, key, keysArgs(key, args));
|
||||
}
|
||||
|
||||
public CompletableFuture<RedisCacheResult> sremAsync(String key, Serializable... args) {
|
||||
return sendAsync("SREM", key, args);
|
||||
}
|
||||
public CompletableFuture<RedisCacheResult> sremAsync(String key, String... args) {
|
||||
return sendAsync(RedisCommand.SREM, key, keysArgs(key, args));
|
||||
}*/
|
||||
|
||||
//--------------------- hm ------------------------------
|
||||
|
||||
@@ -286,14 +293,14 @@ public class MyRedisCacheSource extends RedisCacheSource {
|
||||
setHmsAsync(key, kv).join();
|
||||
}
|
||||
|
||||
public CompletableFuture<RedisCacheResult> setHmsAsync(String key, Map<Serializable, Serializable> kv) {
|
||||
List<Serializable> args = new ArrayList();
|
||||
public CompletableFuture<RedisCacheResult> setHmsAsync(String key, Map<String, Serializable> kv) {
|
||||
List<String> args = new ArrayList();
|
||||
kv.forEach((k, v) -> {
|
||||
args.add(k);
|
||||
args.add(v);
|
||||
args.add(v + "");
|
||||
});
|
||||
|
||||
return sendAsync("HMSET", key, args.toArray(Serializable[]::new));
|
||||
return sendAsync(RedisCommand.HMSET, key, keysArgs(key, args.toArray(String[]::new)));
|
||||
}
|
||||
|
||||
public String getHm(String key, String field) {
|
||||
|
Reference in New Issue
Block a user