summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-08-01 19:01:40 +0200
committerantirez <antirez@gmail.com>2018-08-01 19:04:53 +0200
commit2f282aee0b8e500697b627254b170f21d93dd4a8 (patch)
treea70cf9aecb8fd310d569d994d5c634bd1f5ee449
parent29226a3919ef1f74bc161b31972193ce30bc0ed6 (diff)
downloadredis-2f282aee0b8e500697b627254b170f21d93dd4a8.tar.gz
Fix zslUpdateScore() edge case.
When the element new score is the same of prev/next node, the lexicographical order kicks in, so we can safely update the node in place only when the new score is strictly between the adjacent nodes but never equal to one of them. Technically speaking we could do extra checks to make sure that even if the score is the same as one of the adjacent nodes, we can still update on place, but this rarely happens, so probably not a good deal to make it more complex. Related to #5179.
-rw-r--r--src/t_zset.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/t_zset.c b/src/t_zset.c
index a794b44c3..db381b592 100644
--- a/src/t_zset.c
+++ b/src/t_zset.c
@@ -281,8 +281,8 @@ zskiplistNode *zslUpdateScore(zskiplist *zsl, double curscore, sds ele, double n
/* If the node, after the score update, would be still exactly
* at the same position, we can just update the score without
* actually removing and re-inserting the element in the skiplist. */
- if ((x->backward == NULL || x->backward->score <= newscore) &&
- (x->level[0].forward == NULL || x->level[0].forward->score >= newscore))
+ if ((x->backward == NULL || x->backward->score < newscore) &&
+ (x->level[0].forward == NULL || x->level[0].forward->score > newscore))
{
x->score = newscore;
return x;