Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
34a719d2
Commit
34a719d2
authored
Sep 17, 2010
by
antirez
Browse files
try to parse the request in a smarter way to gain speed... work in progress
parent
2b00385d
Changes
2
Show whitespace changes
Inline
Side-by-side
src/networking.c
View file @
34a719d2
...
...
@@ -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
;
}
...
...
src/redis.h
View file @
34a719d2
...
...
@@ -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 */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment