redis异常在这里

err protocol error: invalid multibulk length

finally, I figured it out.
the length of args of the API command MSET can’t be bigger than 1024 * 1024, so the length of the array KeyValuePair
(RedisKey, RedisValue)[] values cant be bigger than 524288, so I limit it to 524287, then it works.
I hope this would be helpful others.

redis官方源码:

/* We know for sure there is a whole line since newline != NULL,
         * so go ahead and find out the multi bulk length. */
        redisAssertWithInfo(c,NULL,c->querybuf[0] == '*');
        ok = string2ll(c->querybuf+1,newline-(c->querybuf+1),&ll);
        if (!ok || ll > 1024*1024) {
            addReplyError(c,"Protocol error: invalid multibulk length");
            setProtocolError(c,pos);
            return REDIS_ERR;
        }

存储的时候分段吧

public void storeResult(Integer totalCount, String matrixActionKey, List<String> resultList, String blueBall) {
        /* 过滤前的个数*/
        if (totalCount >= 10000) {
            /* 红球结果 过期时间 5分钟*/
            Boolean isDiv = Boolean.TRUE;
            while (isDiv) {
                List<String> storeList;
                if (resultList.size() - (524287) > 0) {
                    storeList = resultList.subList(0, 524287 - 1);
                    resultList = resultList.subList(524287, resultList.size() - 1);
                } else {
                    storeList = resultList;
                    isDiv = Boolean.FALSE;
                }
                redisService.kryoLPushStr(matrixActionKey, storeList.toArray(new String[storeList.size()]));
            }
            redisService.expire(matrixActionKey, RedisConstant.EXPIRE_TIME_SECOND_FIVE_MINUTE);
            /* 篮球号码存一下*/
            redisService.kryoSetEx(RedisConstant.getMatrixActionBlueKey(matrixActionKey), RedisConstant
                    .EXPIRE_TIME_SECOND_FIVE_MINUTE, blueBall);
        }

    }

你可能感兴趣的:(redis)