战斗数据进Redis缓存

仅保存最新数据
This commit is contained in:
Yutousama 2020-03-30 17:36:59 +08:00
parent 10480cd5de
commit b69b2f3755

View File

@ -1,10 +1,12 @@
package com.yutou.jianrdb.Mapper;
import com.alibaba.fastjson.JSONArray;
import com.yutou.jianrdb.Bean.GameInfoLog;
import com.yutou.jianrdb.Bean.MapNode;
import com.yutou.jianrdb.Dao.MapNodeDao;
import com.yutou.maptop.Bean.UserTeam;
import com.yutou.mybatis.ZsShipType;
import com.yutou.utlis.RedisUtlis;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -30,9 +32,26 @@ public class MapNodeService {
public List<MapNode> selectMapByNode(String chapterName, String levelName) {
return dao.selectMapByNode(chapterName, levelName);
}
public List<GameInfoLog> selectNodeByMid(int nodeId, int limit, int count) {
return dao.selectNodeByMid("%"+nodeId+"%", limit, count);
String tmp=RedisUtlis.get(nodeId+"");
List<GameInfoLog> list;
if(tmp==null){
list=dao.selectNodeByMid("%"+nodeId+"%", limit, count);
tmp=JSONArray.toJSONString(list);
RedisUtlis.set(nodeId+"",tmp);
}else{
list= JSONArray.parseArray(tmp,GameInfoLog.class);
new Thread(new Runnable() {
@Override
public void run() {
List<GameInfoLog> tmpList=dao.selectNodeByMid("%"+nodeId+"%", limit, count);
String tmp=JSONArray.toJSONString(tmpList);
RedisUtlis.set(nodeId+"",tmp);
}
}).start();
}
return list;
}
public List<ZsShipType> selectAllShipType(){