Skip to content

Commit

Permalink
Merge pull request redis#2774 from rouzier/blocking-list-commands-sup…
Browse files Browse the repository at this point in the history
…port-milliseconds-floating

Added millisecond resolution for blpop command && friends
  • Loading branch information
antirez authored Mar 12, 2019
2 parents fba6e26 + eca0187 commit e5acc5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/blocked.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,25 @@ int serveClientBlockedOnList(client *receiver, robj *key, robj *dstkey, redisDb
* is zero. */
int getTimeoutFromObjectOrReply(client *c, robj *object, mstime_t *timeout, int unit) {
long long tval;
long double ftval;

if (getLongLongFromObjectOrReply(c,object,&tval,
"timeout is not an integer or out of range") != C_OK)
return C_ERR;
if (unit == UNIT_SECONDS) {
if (getLongDoubleFromObjectOrReply(c,object,&ftval,
"timeout is not an float or out of range") != C_OK)
return C_ERR;
tval = (long long) (ftval * 1000.0);
} else {
if (getLongLongFromObjectOrReply(c,object,&tval,
"timeout is not an integer or out of range") != C_OK)
return C_ERR;
}

if (tval < 0) {
addReplyError(c,"timeout is negative");
return C_ERR;
}

if (tval > 0) {
if (unit == UNIT_SECONDS) tval *= 1000;
tval += mstime();
}
*timeout = tval;
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/type/list.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,11 @@ start_server {

test "$pop: with non-integer timeout" {
set rd [redis_deferring_client]
$rd $pop blist1 1.1
assert_error "ERR*not an integer*" {$rd read}
r del blist1
$rd $pop blist1 0.1
r rpush blist1 foo
assert_equal {blist1 foo} [$rd read]
assert_equal 0 [r exists blist1]
}

test "$pop: with zero timeout should block indefinitely" {
Expand Down

0 comments on commit e5acc5e

Please sign in to comment.