Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
c7f93143
Commit
c7f93143
authored
Jun 09, 2014
by
Salvatore Sanfilippo
Browse files
Merge pull request #1669 from mattsta/blpop-internally-added-keys
Fix blocking operations from missing new lists
parents
6a13193d
33f943b4
Changes
4
Show whitespace changes
Inline
Side-by-side
src/db.c
View file @
c7f93143
...
...
@@ -95,6 +95,7 @@ void dbAdd(redisDb *db, robj *key, robj *val) {
int
retval
=
dictAdd
(
db
->
dict
,
copy
,
val
);
redisAssertWithInfo
(
NULL
,
key
,
retval
==
REDIS_OK
);
if
(
val
->
type
==
REDIS_LIST
)
signalListAsReady
(
db
,
key
);
if
(
server
.
cluster_enabled
)
slotToKeyAdd
(
key
);
}
...
...
src/redis.h
View file @
c7f93143
...
...
@@ -1037,6 +1037,7 @@ void listTypeConvert(robj *subject, int enc);
void
unblockClientWaitingData
(
redisClient
*
c
);
void
handleClientsBlockedOnLists
(
void
);
void
popGenericCommand
(
redisClient
*
c
,
int
where
);
void
signalListAsReady
(
redisDb
*
db
,
robj
*
key
);
/* MULTI/EXEC/WATCH... */
void
unwatchAllKeys
(
redisClient
*
c
);
...
...
src/t_list.c
View file @
c7f93143
...
...
@@ -29,8 +29,6 @@
#include "redis.h"
void
signalListAsReady
(
redisClient
*
c
,
robj
*
key
);
/*-----------------------------------------------------------------------------
* List API
*----------------------------------------------------------------------------*/
...
...
@@ -297,15 +295,12 @@ void listTypeConvert(robj *subject, int enc) {
void
pushGenericCommand
(
redisClient
*
c
,
int
where
)
{
int
j
,
waiting
=
0
,
pushed
=
0
;
robj
*
lobj
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
int
may_have_waiting_clients
=
(
lobj
==
NULL
);
if
(
lobj
&&
lobj
->
type
!=
REDIS_LIST
)
{
addReply
(
c
,
shared
.
wrongtypeerr
);
return
;
}
if
(
may_have_waiting_clients
)
signalListAsReady
(
c
,
c
->
argv
[
1
]);
for
(
j
=
2
;
j
<
c
->
argc
;
j
++
)
{
c
->
argv
[
j
]
=
tryObjectEncoding
(
c
->
argv
[
j
]);
if
(
!
lobj
)
{
...
...
@@ -709,7 +704,6 @@ void rpoplpushHandlePush(redisClient *c, robj *dstkey, robj *dstobj, robj *value
if
(
!
dstobj
)
{
dstobj
=
createZiplistObject
();
dbAdd
(
c
->
db
,
dstkey
,
dstobj
);
signalListAsReady
(
c
,
dstkey
);
}
signalModifiedKey
(
c
->
db
,
dstkey
);
listTypePush
(
dstobj
,
value
,
REDIS_HEAD
);
...
...
@@ -849,19 +843,19 @@ void unblockClientWaitingData(redisClient *c) {
* made by a script or in the context of MULTI/EXEC.
*
* The list will be finally processed by handleClientsBlockedOnLists() */
void
signalListAsReady
(
redis
Client
*
c
,
robj
*
key
)
{
void
signalListAsReady
(
redis
Db
*
db
,
robj
*
key
)
{
readyList
*
rl
;
/* No clients blocking for this key? No need to queue it. */
if
(
dictFind
(
c
->
db
->
blocking_keys
,
key
)
==
NULL
)
return
;
if
(
dictFind
(
db
->
blocking_keys
,
key
)
==
NULL
)
return
;
/* Key was already signaled? No need to queue it again. */
if
(
dictFind
(
c
->
db
->
ready_keys
,
key
)
!=
NULL
)
return
;
if
(
dictFind
(
db
->
ready_keys
,
key
)
!=
NULL
)
return
;
/* Ok, we need to queue this key into server.ready_keys. */
rl
=
zmalloc
(
sizeof
(
*
rl
));
rl
->
key
=
key
;
rl
->
db
=
c
->
db
;
rl
->
db
=
db
;
incrRefCount
(
key
);
listAddNodeTail
(
server
.
ready_keys
,
rl
);
...
...
@@ -869,7 +863,7 @@ void signalListAsReady(redisClient *c, robj *key) {
* to avoid adding it multiple times into a list with a simple O(1)
* check. */
incrRefCount
(
key
);
redisAssert
(
dictAdd
(
c
->
db
->
ready_keys
,
key
,
NULL
)
==
DICT_OK
);
redisAssert
(
dictAdd
(
db
->
ready_keys
,
key
,
NULL
)
==
DICT_OK
);
}
/* This is a helper function for handleClientsBlockedOnLists(). It's work
...
...
tests/unit/type/list.tcl
View file @
c7f93143
...
...
@@ -408,6 +408,29 @@ start_server {
$rd read
}
{}
test
"BLPOP when new key is moved into place"
{
set rd
[
redis_deferring_client
]
$rd blpop foo 5
r lpush bob abc def hij
r rename bob foo
$rd read
}
{
foo hij
}
test
"BLPOP when result key is created by SORT..STORE"
{
set rd
[
redis_deferring_client
]
# zero out list from previous test without explicit delete
r lpop foo
r lpop foo
r lpop foo
$rd blpop foo 5
r lpush notfoo hello hola aguacate konichiwa zanzibar
r sort notfoo ALPHA store foo
$rd read
}
{
foo aguacate
}
foreach
{
pop
}
{
BLPOP BRPOP
}
{
test
"
$pop:
with single empty list argument"
{
set rd
[
redis_deferring_client
]
...
...
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