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
c8a0070a
Commit
c8a0070a
authored
Dec 06, 2010
by
Pieter Noordhuis
Browse files
Move timeout logic
parent
bc8ffafe
Changes
1
Show whitespace changes
Inline
Side-by-side
src/t_list.c
View file @
c8a0070a
...
@@ -817,20 +817,20 @@ int handleClientsWaitingListPush(redisClient *c, robj *key, robj *ele) {
...
@@ -817,20 +817,20 @@ int handleClientsWaitingListPush(redisClient *c, robj *key, robj *ele) {
return
1
;
return
1
;
}
}
int
check
Timeout
(
redisClient
*
c
,
robj
*
object
,
time_t
*
timeout
)
{
int
get
Timeout
FromObjectOrReply
(
redisClient
*
c
,
robj
*
object
,
time_t
*
timeout
)
{
long
long
lltimeout
;
long
tval
;
if
(
getLong
Long
FromObject
(
object
,
&
lltimeout
)
!=
REDIS_OK
)
{
if
(
getLongFromObject
OrReply
(
c
,
object
,
&
tval
,
addReplyError
(
c
,
"timeout is not an integer
"
);
"timeout is not an integer
or out of range"
)
!=
REDIS_OK
)
return
REDIS_ERR
;
return
REDIS_ERR
;
}
if
(
lltimeout
<
0
)
{
if
(
tval
<
0
)
{
addReplyError
(
c
,
"timeout is negative"
);
addReplyError
(
c
,
"timeout is negative"
);
return
REDIS_ERR
;
return
REDIS_ERR
;
}
}
*
timeout
=
lltimeout
;
if
(
tval
>
0
)
tval
+=
time
(
NULL
);
*
timeout
=
tval
;
return
REDIS_OK
;
return
REDIS_OK
;
}
}
...
@@ -841,9 +841,8 @@ void blockingPopGenericCommand(redisClient *c, int where) {
...
@@ -841,9 +841,8 @@ void blockingPopGenericCommand(redisClient *c, int where) {
time_t
timeout
;
time_t
timeout
;
int
j
;
int
j
;
if
(
check
Timeout
(
c
,
c
->
argv
[
c
->
argc
-
1
],
&
timeout
)
!=
REDIS_OK
)
{
if
(
get
Timeout
FromObjectOrReply
(
c
,
c
->
argv
[
c
->
argc
-
1
],
&
timeout
)
!=
REDIS_OK
)
return
;
return
;
}
for
(
j
=
1
;
j
<
c
->
argc
-
1
;
j
++
)
{
for
(
j
=
1
;
j
<
c
->
argc
-
1
;
j
++
)
{
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
j
]);
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
j
]);
...
@@ -894,7 +893,6 @@ void blockingPopGenericCommand(redisClient *c, int where) {
...
@@ -894,7 +893,6 @@ void blockingPopGenericCommand(redisClient *c, int where) {
}
}
/* If the list is empty or the key does not exists we must block */
/* If the list is empty or the key does not exists we must block */
if
(
timeout
>
0
)
timeout
+=
time
(
NULL
);
blockForKeys
(
c
,
c
->
argv
+
1
,
c
->
argc
-
2
,
timeout
,
NULL
);
blockForKeys
(
c
,
c
->
argv
+
1
,
c
->
argc
-
2
,
timeout
,
NULL
);
}
}
...
@@ -909,9 +907,8 @@ void brpopCommand(redisClient *c) {
...
@@ -909,9 +907,8 @@ void brpopCommand(redisClient *c) {
void
brpoplpushCommand
(
redisClient
*
c
)
{
void
brpoplpushCommand
(
redisClient
*
c
)
{
time_t
timeout
;
time_t
timeout
;
if
(
check
Timeout
(
c
,
c
->
argv
[
3
],
&
timeout
)
!=
REDIS_OK
)
{
if
(
get
Timeout
FromObjectOrReply
(
c
,
c
->
argv
[
3
],
&
timeout
)
!=
REDIS_OK
)
return
;
return
;
}
robj
*
key
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
robj
*
key
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
...
@@ -922,8 +919,6 @@ void brpoplpushCommand(redisClient *c) {
...
@@ -922,8 +919,6 @@ void brpoplpushCommand(redisClient *c) {
* returns immediately. */
* returns immediately. */
addReply
(
c
,
shared
.
nullmultibulk
);
addReply
(
c
,
shared
.
nullmultibulk
);
}
else
{
}
else
{
if
(
timeout
>
0
)
timeout
+=
time
(
NULL
);
/* The list is empty and the client blocks. */
/* The list is empty and the client blocks. */
blockForKeys
(
c
,
c
->
argv
+
1
,
1
,
timeout
,
c
->
argv
[
2
]);
blockForKeys
(
c
,
c
->
argv
+
1
,
1
,
timeout
,
c
->
argv
[
2
]);
}
}
...
...
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