...
|
...
|
@@ -175,12 +175,15 @@ public class RedisCommonUtil { |
|
|
return result;
|
|
|
}*/
|
|
|
|
|
|
public static Map<String,String> cmd_get(String host,int port,int selectIndex,String keyName){
|
|
|
public static Map<String,String> cmd_get(String host,int port,String authPwd,int selectIndex,String keyName){
|
|
|
Map<String,String> result=new HashMap<String,String>();
|
|
|
Jedis client =null;
|
|
|
try {
|
|
|
client=new Jedis(host, port);
|
|
|
// client.select(selectIndex); redis数据库支持select,但是twemproxy不支持select
|
|
|
if(StringUtils.isNotBlank(authPwd)){
|
|
|
client.auth(authPwd);
|
|
|
}
|
|
|
String rtn = client.get(keyName);
|
|
|
result.put("result",rtn);
|
|
|
result.put("flag","suc");
|
...
|
...
|
@@ -196,12 +199,15 @@ public class RedisCommonUtil { |
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static Map<String,String> cmd_ttl(String host,int port,int selectIndex,String keyName){
|
|
|
public static Map<String,String> cmd_ttl(String host,int port,String authPwd,int selectIndex,String keyName){
|
|
|
Map<String,String> result=new HashMap<String,String>();
|
|
|
Jedis client =null;
|
|
|
try {
|
|
|
client=new Jedis(host, port);
|
|
|
// client.select(selectIndex); redis数据库支持select,但是twemproxy不支持select
|
|
|
if(StringUtils.isNotBlank(authPwd)){
|
|
|
client.auth(authPwd);
|
|
|
}
|
|
|
Long rtn = client.ttl(keyName);
|
|
|
result.put("result",String.valueOf(rtn));
|
|
|
result.put("flag","suc");
|
...
|
...
|
@@ -217,12 +223,15 @@ public class RedisCommonUtil { |
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static Map<String,String> cmd_hget(String host,int port,int selectIndex,String keyName,String field){
|
|
|
public static Map<String,String> cmd_hget(String host,int port,String authPwd,int selectIndex,String keyName,String field){
|
|
|
Map<String,String> result=new HashMap<String,String>();
|
|
|
Jedis client =null;
|
|
|
try {
|
|
|
client=new Jedis(host, port);
|
|
|
// client.select(selectIndex);
|
|
|
if(StringUtils.isNotBlank(authPwd)){
|
|
|
client.auth(authPwd);
|
|
|
}
|
|
|
String rtn = client.hget(keyName,field);
|
|
|
result.put("result",rtn);
|
|
|
result.put("flag","suc");
|
...
|
...
|
@@ -239,12 +248,15 @@ public class RedisCommonUtil { |
|
|
}
|
|
|
|
|
|
//list
|
|
|
public static Map<String,String> cmd_lrange(String host,int port,int selectIndex,String keyName,int startIndex,int endIndex){
|
|
|
public static Map<String,String> cmd_lrange(String host,int port,String authPwd,int selectIndex,String keyName,int startIndex,int endIndex){
|
|
|
Map<String,String> result=new HashMap<String,String>();
|
|
|
Jedis client =null;
|
|
|
try {
|
|
|
client=new Jedis(host, port);
|
|
|
// client.select(selectIndex);
|
|
|
if(StringUtils.isNotBlank(authPwd)){
|
|
|
client.auth(authPwd);
|
|
|
}
|
|
|
List<String> rtnLs = client.lrange(keyName,startIndex,endIndex);
|
|
|
result.put("result", (rtnLs==null||rtnLs.size()<=0)?"":JSON.toJSONString(rtnLs));
|
|
|
result.put("flag","suc");
|
...
|
...
|
@@ -261,12 +273,15 @@ public class RedisCommonUtil { |
|
|
}
|
|
|
|
|
|
//set
|
|
|
public static Map<String,String> cmd_smembers(String host,int port,int selectIndex,String keyName){
|
|
|
public static Map<String,String> cmd_smembers(String host,int port,String authPwd,int selectIndex,String keyName){
|
|
|
Map<String,String> result=new HashMap<String,String>();
|
|
|
Jedis client =null;
|
|
|
try {
|
|
|
client=new Jedis(host, port);
|
|
|
// client.select(selectIndex);
|
|
|
if(StringUtils.isNotBlank(authPwd)){
|
|
|
client.auth(authPwd);
|
|
|
}
|
|
|
Set<String> rtnLs = client.smembers(keyName);
|
|
|
result.put("result", (rtnLs==null||rtnLs.size()<=0)?"":JSON.toJSONString(rtnLs));
|
|
|
result.put("flag","suc");
|
...
|
...
|
@@ -283,12 +298,15 @@ public class RedisCommonUtil { |
|
|
}
|
|
|
|
|
|
//map
|
|
|
public static Map<String,String> cmd_hmget(String host,int port,int selectIndex,String keyName,String... args){
|
|
|
public static Map<String,String> cmd_hmget(String host,int port,String authPwd,int selectIndex,String keyName,String... args){
|
|
|
Map<String,String> result=new HashMap<String,String>();
|
|
|
Jedis client =null;
|
|
|
try {
|
|
|
client=new Jedis(host, port);
|
|
|
// client.select(selectIndex);
|
|
|
if(StringUtils.isNotBlank(authPwd)){
|
|
|
client.auth(authPwd);
|
|
|
}
|
|
|
List<String> rtnLs = client.hmget(keyName,args);
|
|
|
result.put("result", (rtnLs==null||rtnLs.size()<=0)?"":JSON.toJSONString(rtnLs));
|
|
|
result.put("flag","suc");
|
...
|
...
|
@@ -401,7 +419,7 @@ public class RedisCommonUtil { |
|
|
//removeRedisKeyByPrefix("192.168.103.93",16379,"yh:users:userInfo");
|
|
|
//System.out.println(getRedisIsSlave("192.168.102.222", 6379, "192.168.102.222",6379));
|
|
|
|
|
|
System.out.println(cmd_get("192.168.103.94",6379,1,"qc"));
|
|
|
System.out.println(cmd_get("192.168.103.94",6379,"",1,"qc"));
|
|
|
|
|
|
System.out.println(cmd_flushAll("192.168.103.94",6379));
|
|
|
}
|
...
|
...
|
|