...
|
...
|
@@ -6,6 +6,8 @@ import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import redis.clients.jedis.Jedis;
|
|
|
import redis.clients.jedis.ScanParams;
|
|
|
import redis.clients.jedis.ScanResult;
|
|
|
import redis.clients.jedis.exceptions.JedisDataException;
|
|
|
|
|
|
import java.util.*;
|
...
|
...
|
@@ -280,13 +282,81 @@ public class RedisCommonUtil { |
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* redis 清除缓存 ,根据前缀
|
|
|
*/
|
|
|
public static void removeRedisKeyByPrefix(String host,int port,int selectIndex,String prefix){
|
|
|
if(StringUtils.isBlank(prefix)){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
Jedis client =null;
|
|
|
try {
|
|
|
client=new Jedis(host, port);
|
|
|
ScanParams scanParams = new ScanParams();
|
|
|
scanParams.match(prefix+"*");
|
|
|
|
|
|
Long total=0L;
|
|
|
List<String> list;
|
|
|
ScanResult<String> sr;
|
|
|
String nextCursor="0";
|
|
|
do {
|
|
|
sr = client.scan(nextCursor,scanParams);
|
|
|
nextCursor=new String(sr.getCursorAsBytes(),"UTF-8");
|
|
|
if(sr!=null){
|
|
|
list = sr.getResult();
|
|
|
if(list!=null&&list.size()>0){
|
|
|
total = total+(list.size());
|
|
|
System.out.println(list);
|
|
|
for(String key:list){
|
|
|
client.del(key);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
System.out.println(nextCursor);
|
|
|
}while (!nextCursor.equals("0"));
|
|
|
|
|
|
System.out.println("total is "+total);
|
|
|
}catch (Exception e){
|
|
|
logger.error(e.toString());
|
|
|
}finally {
|
|
|
if(client!=null){
|
|
|
client.close();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* public static Map<String,String> cmd_set(String host,int port,int selectIndex,String keyName,String value){
|
|
|
Map<String,String> result=new HashMap<String,String>();
|
|
|
Jedis client =null;
|
|
|
try {
|
|
|
client=new Jedis(host, port);
|
|
|
// client.select(selectIndex); redis数据库支持select,但是twemproxy不支持select
|
|
|
client.set(keyName,value);
|
|
|
String rtn = client.get(keyName);
|
|
|
result.put("result",rtn);
|
|
|
result.put("flag","suc");
|
|
|
}catch (Exception e){
|
|
|
logger.error(e.toString());
|
|
|
result.put("result",e.toString());
|
|
|
result.put("flag","fail");
|
|
|
}finally {
|
|
|
if(client!=null){
|
|
|
client.close();
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}*/
|
|
|
|
|
|
public static void main(String args[]){
|
|
|
/* for(int i=0;i<1000;i++){
|
|
|
System.out.println(cmd_set("192.168.103.93",16379,1,"name"+i,""+i));
|
|
|
}*/
|
|
|
//System.out.println(getRedisInfo("172.16.6.104",6389));
|
|
|
// System.out.println(getRedisInfo("192.168.103.94",16379));
|
|
|
System.out.println(cmd_get("192.168.103.93", 16379,1, "qc"));
|
|
|
// System.out.println(cmd_get("192.168.103.93", 16379,1, "qc"));
|
|
|
removeRedisKeyByPrefix("192.168.103.93",16379,1,"name");
|
|
|
//System.out.println(getRedisIsSlave("192.168.102.222", 6379, "192.168.102.222",6379));
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|