StackExchange.Redis icon indicating copy to clipboard operation
StackExchange.Redis copied to clipboard

ERR Protocol error: invalid multibulk length

Open zhdaniel opened this issue 11 years ago • 15 comments

Hi, mgravell. I got this error when I use the multi set keys to insert about 1 million records to redis at one time, i.e. the API in the StackExchange.Redis

bool StringSet(KeyValuePair<RedisKey, RedisValue>[] values, When when = When.Always, CommandFlags flags = CommandFlags.None);

and I searched the redis source code for ERR Protocol error: invalid multibulk length, but I'm sure my each value size is not bigger than 512MB, I can't figure out why, could you give me your help?

StackExchange.Redis.RedisServerException: ERR Protocol error: invalid multibulk length
   at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server)
   at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor`1 processor, ServerEndPoint server)

zhdaniel avatar May 04 '15 03:05 zhdaniel

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.

zhdaniel avatar May 04 '15 08:05 zhdaniel

Wow; I wonder if that is documented anywhere. Good find! Please could you reopen? I would like to change the code to work more appropriately: either throw before sending, or split the work into multiple commands. On 4 May 2015 9:48 am, "Daniel Zhang" [email protected] wrote:

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.

— Reply to this email directly or view it on GitHub https://github.com/StackExchange/StackExchange.Redis/issues/201#issuecomment-98639005 .

mgravell avatar May 04 '15 09:05 mgravell

with pleasure ;)

zhdaniel avatar May 04 '15 09:05 zhdaniel

Hi @mgravell, I searched this error message at: https://github.com/antirez/redis/blob/6c60526db91e23fb2d666fc52facc9a11780a2a3/src/networking.c#L1024 I think this should be the limitation of the MSET args length, though there is no document about this.

zhdaniel avatar May 04 '15 09:05 zhdaniel

i still got this exception today. is this fixed ?

lin2code avatar Aug 16 '16 09:08 lin2code

@631320085 not yet

zhdaniel avatar Aug 16 '16 09:08 zhdaniel

Sorry for last comment, i was got this exception from ServiceStack.Redis yesterday. But today i use StackExchange.Redis SetAdd 1million values got a timeout exception, then i changed option's ConnectTimeout and SyncTimeout , it's worked. well done. @zhdaniel

lin2code avatar Aug 17 '16 16:08 lin2code

+1

hckuo2 avatar Sep 18 '16 06:09 hckuo2

+1

dtraykov avatar Dec 28 '16 09:12 dtraykov

+1

vpagliari avatar Mar 30 '17 17:03 vpagliari

Do we have a date for when this is going to be fixed? I ran into this error today when we loaded data....

aspnerd avatar Jul 10 '17 20:07 aspnerd

k, I'll take responsibility for this and get it fixed next deploy. sorry - it slipped through the cracks because it got closed

On 10 Jul 2017 9:58 p.m., "aspnerd" [email protected] wrote:

When is this going to be fixed? I hit this error today once we loaded our data. Not good.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/StackExchange/StackExchange.Redis/issues/201#issuecomment-314239596, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDsFRjAGP-2Mf4vLxkTXLUMS1jNfcRks5sMpCNgaJpZM4EPAmj .

mgravell avatar Jul 10 '17 22:07 mgravell

very glad to hear that.

zhdaniel avatar Jul 17 '17 13:07 zhdaniel

it's in Redis source code

/* 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; }

circlechu avatar Apr 26 '19 02:04 circlechu

The error message on this should be more specific to avoid having to search and find this GitHub issue.

ryebread321 avatar May 02 '21 16:05 ryebread321