Blocking POP: use a dictionary to store keys clinet side.

To store the keys we block for during a blocking pop operation, in the
case the client is blocked for more data to arrive, we used a simple
linear array of redis objects, in the blockingState structure:

    robj **keys;
    int count;

However in order to fix issue #801 we also use a dictionary in order to
avoid to end in the blocked clients queue for the same key multiple
times with the same client.

The dictionary was only temporary, just to avoid duplicates, but since
we create / destroy it there is no point in doing this duplicated work,
so this commit simply use a dictionary as the main structure to store
the keys we are blocked for. So instead of the previous fields we now
just have:

    dict *keys;

This simplifies the code and reduces the work done by the server during
a blocking POP operation.
This commit is contained in:
antirez
2012-12-02 20:36:18 +01:00
parent fbf3e33d18
commit 07a9f85405
3 changed files with 20 additions and 36 deletions

View File

@ -350,9 +350,8 @@ typedef struct multiState {
} multiState;
typedef struct blockingState {
robj **keys; /* The key we are waiting to terminate a blocking
dict *keys; /* The keys we are waiting to terminate a blocking
* operation such as BLPOP. Otherwise NULL. */
int count; /* Number of blocking keys */
time_t timeout; /* Blocking operation timeout. If UNIX current time
* is >= timeout then the operation timed out. */
robj *target; /* The key that should receive the element,