summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-11-17 16:02:11 +0100
committerantirez <antirez@gmail.com>2017-12-01 10:24:25 +0100
commit9dc79c039a16674458a39c8bdfbcfe049f3fae77 (patch)
treefa9cde3a0a63a4be862e3b771d6058aff577f701
parent6919280cc5eb9a35887ddaa528053380d584327a (diff)
downloadredis-9dc79c039a16674458a39c8bdfbcfe049f3fae77.tar.gz
Streams: fix reverse iterator discarding of items out of range.
-rw-r--r--src/t_stream.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/t_stream.c b/src/t_stream.c
index f64824c9b..efb01ef62 100644
--- a/src/t_stream.c
+++ b/src/t_stream.c
@@ -597,11 +597,18 @@ int streamIteratorGetID(streamIterator *si, streamID *id, int64_t *numfields) {
}
}
- /* If we do not emit, we have to discard. */
- int to_discard = (flags & STREAM_ITEM_FLAG_SAMEFIELDS) ?
- *numfields : *numfields*2;
- for (int64_t i = 0; i < to_discard; i++)
- si->lp_ele = lpNext(si->lp,si->lp_ele);
+ /* If we do not emit, we have to discard if we are going
+ * forward, or seek the previous entry if we are going
+ * backward. */
+ if (!si->rev) {
+ int to_discard = (flags & STREAM_ITEM_FLAG_SAMEFIELDS) ?
+ *numfields : *numfields*2;
+ for (int64_t i = 0; i < to_discard; i++)
+ si->lp_ele = lpNext(si->lp,si->lp_ele);
+ } else {
+ int prev_times = 4; /* flag + id ms/seq diff + numfields. */
+ while(prev_times--) si->lp_ele = lpPrev(si->lp,si->lp_ele);
+ }
}
/* End of listpack reached. Try the next/prev radix tree node. */