Commit 665de18a by lixiaozhong

1、避免系统重启产生redis大量脏数据

2、修复登录状态报错的bug
parent 97981223
...@@ -27,15 +27,6 @@ public interface UserCacheService { ...@@ -27,15 +27,6 @@ public interface UserCacheService {
public void offline(String appKey, String clientId, String longChannelId); public void offline(String appKey, String clientId, String longChannelId);
/** /**
* 根据用户id获取存在redis中的数据 例如绑定的服务器ip地址
*
* @param clientId
* @return
*/
public ClientConnectionInfo getById(String appKey, String clientId);
/**
* 根据ClientId从redis获取client信息 * 根据ClientId从redis获取client信息
* *
* @param appKey * @param appKey
......
...@@ -76,8 +76,15 @@ public class UserCacheServiceImpl implements UserCacheService { ...@@ -76,8 +76,15 @@ public class UserCacheServiceImpl implements UserCacheService {
@Override @Override
public void online(String appKey, String clientId, String longChannelId) { public void online(String appKey, String clientId, String longChannelId) {
log.info("ws用户上线保存redis连接ip:" + InitIp.lAN_IP, ",uid:" + longChannelId); log.info("ws用户上线保存redis连接ip:" + InitIp.lAN_IP, ",uid:" + longChannelId);
redisUtils.addForSet(CLIENTS + appKey + clientId, longChannelId);
// 先进行历史数据清理
Set<String> members = redisUtils.getForSetMembers(CLIENTS + appKey + clientId);
if(members != null) {
members.forEach(channelId-> redisUtils.delKey(CLIENT_INFO + channelId));
}
redisUtils.delKey(CLIENTS + appKey + clientId);
redisUtils.addForSet(CLIENTS + appKey + clientId, longChannelId);
redisUtils.hashset(CLIENT_INFO + longChannelId, LAN_IP, InitIp.lAN_IP); redisUtils.hashset(CLIENT_INFO + longChannelId, LAN_IP, InitIp.lAN_IP);
redisUtils.hashset(CLIENT_INFO + longChannelId, ONLINE_STATUS, ONLINE.toString()); redisUtils.hashset(CLIENT_INFO + longChannelId, ONLINE_STATUS, ONLINE.toString());
...@@ -99,26 +106,6 @@ public class UserCacheServiceImpl implements UserCacheService { ...@@ -99,26 +106,6 @@ public class UserCacheServiceImpl implements UserCacheService {
redisUtils.delKey(CLIENT_INFO + longChannelId); redisUtils.delKey(CLIENT_INFO + longChannelId);
} }
/**
* 根据用户id获取存在redis中的数据 例如绑定的服务器ip地址
*
* @param clientId
* @return
*/
@Override
public ClientConnectionInfo getById(String appKey, String clientId) {
Map<String, String> hgetll = redisUtils.hashgetll(CLIENT_INFO + appKey + clientId);
if (hgetll.isEmpty()) {
return null;
}
ClientConnectionInfo appHashValueModel = new ClientConnectionInfo();
appHashValueModel.setLanIp(hgetll.get(LAN_IP));
// appHashValueModel.(Integer.parseInt(hgetll.get(ONLINE_STATUS_KEY)));
return appHashValueModel;
}
@Override @Override
public List<ClientChannelInfo> getIpByClientIdAndOnline(String appKey, String clientId) { public List<ClientChannelInfo> getIpByClientIdAndOnline(String appKey, String clientId) {
...@@ -129,7 +116,7 @@ public class UserCacheServiceImpl implements UserCacheService { ...@@ -129,7 +116,7 @@ public class UserCacheServiceImpl implements UserCacheService {
// 根据 longChannelId 查询信息 // 根据 longChannelId 查询信息
for (String longChannelId : longChannelIds) { for (String longChannelId : longChannelIds) {
String onlineStatus = redisUtils.hashget(CLIENT_INFO + appKey + clientId, ONLINE_STATUS); String onlineStatus = redisUtils.hashget(CLIENT_INFO + longChannelId, ONLINE_STATUS);
String lanIp = redisUtils.hashget(CLIENT_INFO + longChannelId, LAN_IP); String lanIp = redisUtils.hashget(CLIENT_INFO + longChannelId, LAN_IP);
ClientChannelInfo clientChannelInfo = new ClientChannelInfo(); ClientChannelInfo clientChannelInfo = new ClientChannelInfo();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment