mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
try to parse the request in a smarter way to gain speed... work in progress
This commit is contained in:
parent
2b00385d51
commit
34a719d250
@ -28,6 +28,7 @@ redisClient *createClient(int fd) {
|
||||
selectDb(c,0);
|
||||
c->fd = fd;
|
||||
c->querybuf = sdsempty();
|
||||
c->newline = NULL;
|
||||
c->argc = 0;
|
||||
c->argv = NULL;
|
||||
c->bulklen = -1;
|
||||
@ -631,6 +632,7 @@ void resetClient(redisClient *c) {
|
||||
freeClientArgv(c);
|
||||
c->bulklen = -1;
|
||||
c->multibulk = 0;
|
||||
c->newline = NULL;
|
||||
}
|
||||
|
||||
void closeTimedoutClients(void) {
|
||||
@ -672,13 +674,14 @@ again:
|
||||
if (c->flags & REDIS_BLOCKED || c->flags & REDIS_IO_WAIT) return;
|
||||
if (c->bulklen == -1) {
|
||||
/* Read the first line of the query */
|
||||
char *p = strchr(c->querybuf,'\n');
|
||||
size_t querylen;
|
||||
|
||||
if (p) {
|
||||
if (c->newline) {
|
||||
char *p = c->newline;
|
||||
sds query, *argv;
|
||||
int argc, j;
|
||||
|
||||
c->newline = NULL;
|
||||
query = c->querybuf;
|
||||
c->querybuf = sdsempty();
|
||||
querylen = 1+(p-(query));
|
||||
@ -765,8 +768,14 @@ void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask) {
|
||||
return;
|
||||
}
|
||||
if (nread) {
|
||||
size_t oldlen = sdslen(c->querybuf);
|
||||
c->querybuf = sdscatlen(c->querybuf, buf, nread);
|
||||
c->lastinteraction = time(NULL);
|
||||
/* Scan this new piece of the query for the newline. We do this
|
||||
* here in order to make sure we perform this scan just one time
|
||||
* per piece of buffer, leading to an O(N) scan instead of O(N*N) */
|
||||
if (c->bulklen == -1 && c->newline == NULL)
|
||||
c->newline = strchr(c->querybuf+oldlen,'\n');
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -286,6 +286,7 @@ typedef struct redisClient {
|
||||
int dictid;
|
||||
sds querybuf;
|
||||
robj **argv, **mbargv;
|
||||
char *newline; /* pointing to the detected newline in querybuf */
|
||||
int argc, mbargc;
|
||||
long bulklen; /* bulk read len. -1 if not in bulk read mode */
|
||||
int multibulk; /* multi bulk command format active */
|
||||
|
Loading…
Reference in New Issue
Block a user