redis模糊key,scan方法封装
parent
8c37ee1338
commit
fa6937881c
|
@ -239,8 +239,7 @@ public class AreaManager {
|
||||||
//合并排行榜
|
//合并排行榜
|
||||||
|
|
||||||
//查找本服所有排行榜
|
//查找本服所有排行榜
|
||||||
Set<String> keys =new HashSet<>();
|
Set<String> keys = RedisUtil.getInstence().getDimKey(areaId+ "*" + "RANK*",200);
|
||||||
RedisUtil.getInstence().arenaAddDim(areaId+ "*" + "RANK*",200,keys);
|
|
||||||
keys.forEach(k->{
|
keys.forEach(k->{
|
||||||
|
|
||||||
Set<ZSetOperations.TypedTuple<String>> set= RedisUtil.getInstence().getAllZsetRange(k);
|
Set<ZSetOperations.TypedTuple<String>> set= RedisUtil.getInstence().getAllZsetRange(k);
|
||||||
|
@ -269,8 +268,7 @@ public class AreaManager {
|
||||||
//合并名称
|
//合并名称
|
||||||
|
|
||||||
//查找本服所有名称
|
//查找本服所有名称
|
||||||
Set<String> keys =new HashSet<>();
|
Set<String> keys = RedisUtil.getInstence().getDimKey(areaId+ ":" + RedisKey.C_User_Name_Key+"*",200);
|
||||||
RedisUtil.getInstence().arenaAddDim(areaId+ ":" + RedisKey.C_User_Name_Key+"*",200,keys);
|
|
||||||
keys.forEach(k->{
|
keys.forEach(k->{
|
||||||
|
|
||||||
Object oldUserId = RedisUtil.getInstence().get(k);
|
Object oldUserId = RedisUtil.getInstence().get(k);
|
||||||
|
|
|
@ -70,32 +70,29 @@ public class RedisUtil {
|
||||||
new ConvertingCursor<>(redisConnection.scan(match1.build()), redisSerializer::deserialize));
|
new ConvertingCursor<>(redisConnection.scan(match1.build()), redisSerializer::deserialize));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void arenaAddDim(String key, int count, Set<String> keys) throws IOException {
|
|
||||||
Cursor<String> cursor = RedisUtil.getInstence().scan( key, count);
|
|
||||||
while (cursor.hasNext()){
|
|
||||||
//找到一次就添加一次
|
|
||||||
keys.add(cursor.next());
|
|
||||||
}
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模糊删除key
|
* 根据模糊key获取数据
|
||||||
* serverId +":" + key + "*"
|
|
||||||
* @param key
|
* @param key
|
||||||
* @param count
|
* @param count
|
||||||
* @throws IOException
|
* @return
|
||||||
*/
|
*/
|
||||||
public void delDim(String key, int count) throws IOException {
|
public Set<String> getDimKey(String key, int count){
|
||||||
Cursor<String> cursor = RedisUtil.getInstence().scan(key, count);
|
Set<String> keys = new HashSet<>();
|
||||||
while (cursor.hasNext()) {
|
long start = System.currentTimeMillis();
|
||||||
//找到一次就添加一次
|
try {
|
||||||
String next = cursor.next();
|
Cursor<String> cursor = RedisUtil.getInstence().scan(key, count);
|
||||||
LOGGER.info("批量模糊删除{}",next);
|
while (cursor.hasNext()){
|
||||||
RedisUtil.getInstence().del(next);
|
//添加key
|
||||||
|
keys.add(cursor.next());
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
cursor.close();
|
LOGGER.info("scan扫描共耗时:{} ms ,key数量:{},模糊key:{}",System.currentTimeMillis()-start,keys.size(),key);
|
||||||
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 指定缓存失效时间
|
* 指定缓存失效时间
|
||||||
*
|
*
|
||||||
|
|
|
@ -653,7 +653,10 @@ public class DeathPathLogic {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RedisUtil.getInstence().delDim(serverId +":DEATH_PATH*", -1);
|
Set<String> keys = RedisUtil.getInstence().getDimKey(serverId + ":DEATH_PATH*", -1);
|
||||||
|
keys.forEach(key->{
|
||||||
|
RedisUtil.getInstence().del(key);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int nextDiscrete(double[] probs) {
|
public static int nextDiscrete(double[] probs) {
|
||||||
|
|
|
@ -307,7 +307,10 @@ public class HelpHeroLogic {
|
||||||
int serverId = GameApplication.serverId;
|
int serverId = GameApplication.serverId;
|
||||||
String key = serverId +":" + RedisKey.HELP_FIGHT + "*";
|
String key = serverId +":" + RedisKey.HELP_FIGHT + "*";
|
||||||
// 模糊批量删除key
|
// 模糊批量删除key
|
||||||
RedisUtil.getInstence().delDim(key,-1);
|
Set<String> keys = RedisUtil.getInstence().getDimKey(key, -1);
|
||||||
|
keys.forEach(k->{
|
||||||
|
RedisUtil.getInstence().del(k);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue