I'm using hiredis and got some strange error. After reviewing the source code, I found that hiredis discards part of the buffer when its size exceeds 1024. I'm not sure if it's safe to remove this constraint or if there is any way to bypass this problem. Also I'm wondering the reason of this constraint while the maxbuf is set way larger than 1024. Please advice, thanks in advance!
/* Discard part of the buffer when we've consumed at least 1k, to avoid
* doing unnecessary calls to memmove() in sds.c. */
if (r->pos >= 1024) {
if (sdsrange(r->buf,r->pos,-1) < 0) return REDIS_ERR;
r->pos = 0;
r->len = sdslen(r->buf);
}
I found that hiredis discards part of the buffer when its size exceeds 1024.
NO, hiredis does not really discard part of the buffer. Instead, the so-called discarded part have already been consumed/parsed. And sdsrange
moves those unconsumed bytes to the beginning of the buffer.
Obviously this is NOT the root cause of the problem you met. Even if you remove this code, your problem should still exist.