diff --git a/src/rdb.c b/src/rdb.c index c6a88081..1a5a7b2c 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -709,17 +709,23 @@ ssize_t rdbSaveObject(rio *rdb, robj *o) { if ((n = rdbSaveLen(rdb,zsl->length)) == -1) return -1; nwritten += n; + /* We save the skiplist elements from the greatest to the smallest + * (that's trivial since the elements are already ordered in the + * skiplist): this improves the load process, since the next loaded + * element will always be the smaller, so adding to the skiplist + * will always immediately stop at the head, making the insertion + * O(1) instead of O(log(N)). */ zskiplistNode *zn = zsl->tail; while (zn != NULL) { - sds ele = zn->ele; - double *score = &zn->score; - - if ((n = rdbSaveRawString(rdb,(unsigned char*)ele,sdslen(ele))) - == -1) return -1; + if ((n = rdbSaveRawString(rdb, + (unsigned char*)zn->ele,sdslen(zn->ele))) == -1) + { + return -1; + } nwritten += n; - if ((n = rdbSaveBinaryDoubleValue(rdb,*score)) == -1) return -1; + if ((n = rdbSaveBinaryDoubleValue(rdb,zn->score)) == -1) + return -1; nwritten += n; - zn = zn->backward; } } else {