|
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
import com.fdkankan.scene.httpclient.CustomHttpClient;
|
|
import com.fdkankan.scene.httpclient.CustomHttpClient;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Sets;
|
|
import com.google.common.collect.Sets;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -14,6 +15,7 @@ import javax.annotation.Resource;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
+@Slf4j
|
|
@Component
|
|
@Component
|
|
public class RedisClient {
|
|
public class RedisClient {
|
|
|
|
|
|
@@ -59,13 +61,13 @@ public class RedisClient {
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("key", this.genKey(key));
|
|
params.put("key", this.genKey(key));
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis delKey error");
|
|
|
|
- }
|
|
|
|
- Boolean success = jsonObject.getBoolean("data");
|
|
|
|
- if(!success){
|
|
|
|
- throw new RuntimeException("redis delKey failed");
|
|
|
|
- }
|
|
|
|
|
|
+// if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
+// throw new RuntimeException("redis delKey error");
|
|
|
|
+// }
|
|
|
|
+// Boolean success = jsonObject.getBoolean("data");
|
|
|
|
+// if(!success){
|
|
|
|
+// throw new RuntimeException("redis delKey failed");
|
|
|
|
+// }
|
|
}
|
|
}
|
|
|
|
|
|
public void add(String key, String value){
|
|
public void add(String key, String value){
|
|
@@ -74,9 +76,9 @@ public class RedisClient {
|
|
params.put("key", this.genKey(key));
|
|
params.put("key", this.genKey(key));
|
|
params.put("value", value);
|
|
params.put("value", value);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis add string error");
|
|
|
|
- }
|
|
|
|
|
|
+// if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
+// throw new RuntimeException("redis add string error");
|
|
|
|
+// }
|
|
}
|
|
}
|
|
|
|
|
|
public String get(String key){
|
|
public String get(String key){
|
|
@@ -84,9 +86,9 @@ public class RedisClient {
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("key", this.genKey(key));
|
|
params.put("key", this.genKey(key));
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis get string error");
|
|
|
|
- }
|
|
|
|
|
|
+// if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
+// throw new RuntimeException("redis get string error");
|
|
|
|
+// }
|
|
return jsonObject.getString("data");
|
|
return jsonObject.getString("data");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -96,9 +98,9 @@ public class RedisClient {
|
|
params.put("key", this.genKey(key));
|
|
params.put("key", this.genKey(key));
|
|
params.put("values", JSON.toJSONString(values));
|
|
params.put("values", JSON.toJSONString(values));
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis add set error");
|
|
|
|
- }
|
|
|
|
|
|
+// if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
+// throw new RuntimeException("redis add set error");
|
|
|
|
+// }
|
|
}
|
|
}
|
|
|
|
|
|
public Set<String> sGet(String key){
|
|
public Set<String> sGet(String key){
|
|
@@ -106,9 +108,9 @@ public class RedisClient {
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("key", this.genKey(key));
|
|
params.put("key", this.genKey(key));
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis set getall error");
|
|
|
|
- }
|
|
|
|
|
|
+// if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
+// throw new RuntimeException("redis set getall error");
|
|
|
|
+// }
|
|
List<String> data = jsonObject.getJSONArray("data").toJavaList(String.class);
|
|
List<String> data = jsonObject.getJSONArray("data").toJavaList(String.class);
|
|
return new HashSet<>(data);
|
|
return new HashSet<>(data);
|
|
}
|
|
}
|
|
@@ -119,9 +121,9 @@ public class RedisClient {
|
|
params.put("key", this.genKey(key));
|
|
params.put("key", this.genKey(key));
|
|
params.put("values", values);
|
|
params.put("values", values);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis set srem error");
|
|
|
|
- }
|
|
|
|
|
|
+// if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
+// throw new RuntimeException("redis set srem error");
|
|
|
|
+// }
|
|
}
|
|
}
|
|
|
|
|
|
public void hmset(String key, Map<String, String> values){
|
|
public void hmset(String key, Map<String, String> values){
|
|
@@ -130,9 +132,10 @@ public class RedisClient {
|
|
params.put("key", this.genKey(key));
|
|
params.put("key", this.genKey(key));
|
|
params.put("values", values);
|
|
params.put("values", values);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis hash add error");
|
|
|
|
- }
|
|
|
|
|
|
+ log.info("hash set result:{}", jsonObject);
|
|
|
|
+// if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
+// throw new RuntimeException("redis hash add error");
|
|
|
|
+// }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -141,14 +144,12 @@ public class RedisClient {
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("key", this.genKey(key));
|
|
params.put("key", this.genKey(key));
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis hash hscan error");
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
JSONObject data = jsonObject.getJSONObject("data");
|
|
JSONObject data = jsonObject.getJSONObject("data");
|
|
// 转换为Map<String, String>
|
|
// 转换为Map<String, String>
|
|
Map<String, String> map = new HashMap<>();
|
|
Map<String, String> map = new HashMap<>();
|
|
for (String k : data.keySet()) {
|
|
for (String k : data.keySet()) {
|
|
- map.put(key, jsonObject.getString(key));
|
|
|
|
|
|
+ map.put(k, data.getString(k));
|
|
}
|
|
}
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
@@ -167,9 +168,9 @@ public class RedisClient {
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("key", this.genKey(key));
|
|
params.put("key", this.genKey(key));
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis hash get hvals error");
|
|
|
|
- }
|
|
|
|
|
|
+// if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
+// throw new RuntimeException("redis hash get hvals error");
|
|
|
|
+// }
|
|
List<String> data = jsonObject.getJSONArray("data").toJavaList(String.class);
|
|
List<String> data = jsonObject.getJSONArray("data").toJavaList(String.class);
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
@@ -184,9 +185,9 @@ public class RedisClient {
|
|
params.put("field", field);
|
|
params.put("field", field);
|
|
String url = host + url_hash_hdel;
|
|
String url = host + url_hash_hdel;
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis hash hdel error");
|
|
|
|
- }
|
|
|
|
|
|
+// if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
+// throw new RuntimeException("redis hash hdel error");
|
|
|
|
+// }
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -197,9 +198,9 @@ public class RedisClient {
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("keyValueBatch", keyValMap);
|
|
params.put("keyValueBatch", keyValMap);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis list rPushBatch error");
|
|
|
|
- }
|
|
|
|
|
|
+// if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
+// throw new RuntimeException("redis list rPushBatch error");
|
|
|
|
+// }
|
|
}
|
|
}
|
|
|
|
|
|
public List<String> lGet(String key, long start, long end){
|
|
public List<String> lGet(String key, long start, long end){
|
|
@@ -209,9 +210,9 @@ public class RedisClient {
|
|
params.put("Start", start);
|
|
params.put("Start", start);
|
|
params.put("End", end);
|
|
params.put("End", end);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
JSONObject jsonObject = customHttpClient.postJson(url, params);
|
|
- if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
- throw new RuntimeException("redis list get error");
|
|
|
|
- }
|
|
|
|
|
|
+// if(Objects.isNull(jsonObject) || !"0".equals(jsonObject.getString("status"))){
|
|
|
|
+// throw new RuntimeException("redis list get error");
|
|
|
|
+// }
|
|
|
|
|
|
return jsonObject.getJSONArray("data").toJavaList(String.class);
|
|
return jsonObject.getJSONArray("data").toJavaList(String.class);
|
|
}
|
|
}
|