Authored by qinchao

增加push的redis查询入口

... ... @@ -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));
}
... ...
... ... @@ -198,6 +198,11 @@ public class RedisOperateServiceImpl implements RedisOperateService {
String ip=ipAndPort[0];
int port=Integer.parseInt(ipAndPort[1]);
String authPwd="";
if("10.66.5.182".equals(ip)){
authPwd="redis9646";
}
Map<String,String> rtnMap =null;
/*if(cmd.toLowerCase().startsWith("select ")){
... ... @@ -207,10 +212,10 @@ public class RedisOperateServiceImpl implements RedisOperateService {
rtnMap =RedisCommonUtil.cmd_keys(EnumRedisInfo.getIp(redis), EnumRedisInfo.getPort(redis), selectIndex, keyPattern);
}else*/ if(cmd.toLowerCase().startsWith("get ")){
String key=cmd.substring(4).trim();
rtnMap =RedisCommonUtil.cmd_get(ip, port, selectIndex, key);
rtnMap =RedisCommonUtil.cmd_get(ip, port,authPwd, selectIndex, key);
}else if(cmd.toLowerCase().startsWith("ttl ")){
String key=cmd.substring(4).trim();
rtnMap =RedisCommonUtil.cmd_ttl(ip, port, selectIndex, key);
rtnMap =RedisCommonUtil.cmd_ttl(ip, port,authPwd, selectIndex, key);
}else if(cmd.toLowerCase().startsWith("hget ")){
String keyStr=cmd.substring(4).trim();
String key="";
... ... @@ -234,7 +239,7 @@ public class RedisOperateServiceImpl implements RedisOperateService {
}
}
}
rtnMap =RedisCommonUtil.cmd_hget(ip, port, selectIndex, key, field);
rtnMap =RedisCommonUtil.cmd_hget(ip, port,authPwd, selectIndex, key, field);
}else if(cmd.toLowerCase().startsWith("lrange ")){
String keyStr=cmd.substring(7).trim();
String[] keysParam=keyStr.split(" ");
... ... @@ -264,10 +269,10 @@ public class RedisOperateServiceImpl implements RedisOperateService {
}
}
}
rtnMap =RedisCommonUtil.cmd_lrange(ip, port, selectIndex, key, beginIndex, endIndex);
rtnMap =RedisCommonUtil.cmd_lrange(ip, port,authPwd, selectIndex, key, beginIndex, endIndex);
}else if(cmd.toLowerCase().startsWith("smembers ")){
String key=cmd.substring(9).trim();
rtnMap =RedisCommonUtil.cmd_smembers(ip, port, selectIndex, key);
rtnMap =RedisCommonUtil.cmd_smembers(ip, port, authPwd,selectIndex, key);
}else if(cmd.toLowerCase().startsWith("hmget ")){
String keyParam=cmd.substring(6).trim();
String[] keys=keyParam.split(" ");
... ... @@ -287,7 +292,7 @@ public class RedisOperateServiceImpl implements RedisOperateService {
ls.add(str);
}
}
rtnMap =RedisCommonUtil.cmd_hmget(ip, port, selectIndex, key, ls.toArray(new String[ls.size()]));
rtnMap =RedisCommonUtil.cmd_hmget(ip, port,authPwd, selectIndex, key, ls.toArray(new String[ls.size()]));
}else{
response=new BaseResponse("参数错误:命令不被支持:"+cmd);
return response;
... ...