Commit b9d19371 authored by zhaozhao.zz's avatar zhaozhao.zz
Browse files

ZPOP: unblock multiple clients in right way

parent 3d5e2c62
...@@ -314,8 +314,9 @@ void handleClientsBlockedOnKeys(void) { ...@@ -314,8 +314,9 @@ void handleClientsBlockedOnKeys(void) {
if (de) { if (de) {
list *clients = dictGetVal(de); list *clients = dictGetVal(de);
int numclients = listLength(clients); int numclients = listLength(clients);
unsigned long zcard = zsetLength(o);
while(numclients--) { while(numclients-- && zcard) {
listNode *clientnode = listFirst(clients); listNode *clientnode = listFirst(clients);
client *receiver = clientnode->value; client *receiver = clientnode->value;
...@@ -332,6 +333,7 @@ void handleClientsBlockedOnKeys(void) { ...@@ -332,6 +333,7 @@ void handleClientsBlockedOnKeys(void) {
? ZSET_MIN : ZSET_MAX; ? ZSET_MIN : ZSET_MAX;
unblockClient(receiver); unblockClient(receiver);
genericZpopCommand(receiver,&rl->key,1,where,1,NULL); genericZpopCommand(receiver,&rl->key,1,where,1,NULL);
zcard--;
/* Replicate the command. */ /* Replicate the command. */
robj *argv[2]; robj *argv[2];
......
...@@ -3216,9 +3216,9 @@ void blockingGenericZpopCommand(client *c, int where) { ...@@ -3216,9 +3216,9 @@ void blockingGenericZpopCommand(client *c, int where) {
return; return;
} else { } else {
if (zsetLength(o) != 0) { if (zsetLength(o) != 0) {
/* Non empty zset, this is like a normal Z[REV]POP. */ /* Non empty zset, this is like a normal ZPOP[MIN|MAX]. */
genericZpopCommand(c,&c->argv[j],1,where,1,NULL); genericZpopCommand(c,&c->argv[j],1,where,1,NULL);
/* Replicate it as an Z[REV]POP instead of BZ[REV]POP. */ /* Replicate it as an ZPOP[MIN|MAX] instead of BZPOP[MIN|MAX]. */
rewriteClientCommandVector(c,2, rewriteClientCommandVector(c,2,
where == ZSET_MAX ? shared.zpopmax : shared.zpopmin, where == ZSET_MAX ? shared.zpopmax : shared.zpopmin,
c->argv[j]); c->argv[j]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment