NutzCN Logo
问答 websocket的handler里使用事务处理报错
发布于 2558天前 作者 小小小郑 2318 次浏览 复制 上一个帖子 下一个帖子
标签:

在wshandler里面使用Tran.exe 报如下错误

redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value
	at redis.clients.jedis.Protocol.processError(Protocol.java:117)
	at redis.clients.jedis.Protocol.process(Protocol.java:151)
	at redis.clients.jedis.Protocol.read(Protocol.java:205)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
	at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:216)
	at redis.clients.jedis.Connection.getBulkReply(Connection.java:205)
	at redis.clients.jedis.Jedis.get(Jedis.java:101)
	at org.nutz.integration.jedis.RedisService.get(RedisService.java:60)
	at org.nutz.integration.jedis.RedisService$$NUTZAOP._aop_invoke(RedisService.java:3)
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57)
	at org.nutz.integration.jedis.RedisInterceptor.filter(RedisInterceptor.java:24)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at org.nutz.integration.jedis.RedisService$$NUTZAOP.get(RedisService.java:1)
	at com.game.brag.server.MyHandler$1.run(MyHandler.java:123)
	at org.nutz.trans.Trans.exec(Trans.java:174)
	at org.nutz.trans.Trans.exec(Trans.java:132)
	at com.game.brag.server.MyHandler.action2Round1(MyHandler.java:120)
	at com.game.brag.server.MyHandler.action2Ready(MyHandler.java:245)
	at com.game.brag.server.MyHandler.onMessage(MyHandler.java:80)
	at com.game.brag.server.MyHandler.onMessage(MyHandler.java:1)
	at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:395)
	at org.apache.tomcat.websocket.server.WsFrameServer.sendMessageText(WsFrameServer.java:119)

	at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:495)
	at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:294)
	at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:133)
	at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:82)
	at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:171)

	at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:151)
	at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148)
	at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)

下面是代码片段

public class MyHandler extends SimpleWsHandler {
    
    private void action2Round1(final Integer roomId,final NutMap resp) {
		// TODO Auto-generated method stub
    	
    	final NutMap fp1 = new NutMap();
    	Trans.exec(new Atom(){
		    public void run() {
		    	Set<String> openIdsInRoom = redisService.keys(roomId+Constants.UsersPrefix+"*");
            	Room r = Json.fromJson(Room.class,redisService.get(Constants.RoomPrefix+roomId));
            	Set<String> openIdsInGame = r.getOpenIdsInGame();
            	
        		if(openIdsInRoom != null && openIdsInRoom.size() > 1){
        			List<Poker> pokerList = Poker.createPoker();//初始化一副牌
        			Poker maxPoker = null;
        			for(String openId : openIdsInRoom){
        				User u = Json.fromJson(User.class,redisService.get(roomId+Constants.UsersPrefix+openId));
        				if(u.getUserState() == 1){
        					//两张底牌
        					Poker[] pokerAry = new Poker[5];
        					pokerAry[0] = Poker.getPoker(pokerList);
        					pokerAry[1] = Poker.getPoker(pokerList);
        					resp.setv("action", "backPokers");
        					resp.setv("msg", pokerAry);
        					endpoint.sendJson(session.getId(), resp);
        					//一张面牌
        					pokerAry[2] = Poker.getPoker(pokerList);
        					if(maxPoker == null || maxPoker.compare(pokerAry[2]) == -1){
        						maxPoker = pokerAry[2];
    		        			redisService.hset(Constants.RoomPrefix+roomId, Constants.BeforeIndexField, String.valueOf(u.getIndex()));
        					}
        					fp1.setv(String.valueOf(u.getIndex()), pokerAry[2]);
        					u.setPokerAry(pokerAry);//每个玩家自己的扑克牌
        					u.setUserState(2);//更改游戏状态
        					openIdsInGame.add(roomId+Constants.UsersPrefix+u.getOpenId());//放入games集合
        					u.setScore(0);//初始化积分
        					//更新user的redis缓存
        					redisService.set(roomId+Constants.UsersPrefix+openId, u.toString());
        				}
        			}
        			
        			r.setPokerList(pokerList);
        			redisService.hset(Constants.RoomPrefix+roomId, Constants.RoomField, r.toString());
        		}else{
        			resp.setv("action", "noEnoughUser");
        			resp.setv("msg", "当前在线人数少于2人,无法开始游戏!");
        			endpoint.sendJson(session.getId(), resp);
        		}
		    }
    	});
    	try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("发牌之前等待10s出错!");
		}
		resp.setv("action", "frontPoker1");
		resp.setv("msg", fp1);
		sendAll(resp, roomId);
	}

	
}

4 回复

WRONGTYPE Operation against a key holding the wrong kind of value

这跟事务没有关联性的

报错的是这一句吗?

redisService.get(roomId+Constants.UsersPrefix+openId)

是的 麻烦大佬了,是我粗心了 - -下次注意点

添加回复
请先登陆
回到顶部