From 521ddcce1483d1b8760a108fd5d7df0ae663799a Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 19 May 2011 17:58:29 +0200 Subject: [PATCH] Fix for ZUNIONSTORE bug when there is an empty set among input sets. Regression test added. --- src/t_zset.c | 2 +- tests/unit/type/zset.tcl | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/t_zset.c b/src/t_zset.c index 1c55cb97..19aac3d5 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -1550,7 +1550,7 @@ void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) { } } else if (op == REDIS_OP_UNION) { for (i = 0; i < setnum; i++) { - if (zuiLength(&src[0]) == 0) + if (zuiLength(&src[i]) == 0) continue; while (zuiNext(&src[i],&zval)) { diff --git a/tests/unit/type/zset.tcl b/tests/unit/type/zset.tcl index 37668cfe..761cac49 100644 --- a/tests/unit/type/zset.tcl +++ b/tests/unit/type/zset.tcl @@ -353,6 +353,14 @@ start_server {tags {"zset"}} { assert_equal 0 [r exists dst_key] } + test "ZUNIONSTORE with empty set - $encoding" { + r del zseta zsetb + r zadd zseta 1 a + r zadd zseta 2 b + r zunionstore zsetc 2 zseta zsetb + r zrange zsetc 0 -1 withscores + } {a 1 b 2} + test "ZUNIONSTORE basics - $encoding" { r del zseta zsetb zsetc r zadd zseta 1 a -- 2.45.2