X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/9ec4ea20a71f075a7fc9a2e1d613c339353ee553..890a2ed989274cb09b5cde1def3935e110ec3cb9:/tests/unit/type/zset.tcl diff --git a/tests/unit/type/zset.tcl b/tests/unit/type/zset.tcl index 31604412..761cac49 100644 --- a/tests/unit/type/zset.tcl +++ b/tests/unit/type/zset.tcl @@ -10,7 +10,7 @@ start_server {tags {"zset"}} { if {$encoding == "ziplist"} { r config set zset-max-ziplist-entries 128 r config set zset-max-ziplist-value 64 - } elseif {$encoding == "raw"} { + } elseif {$encoding == "skiplist"} { r config set zset-max-ziplist-entries 0 r config set zset-max-ziplist-value 0 } else { @@ -53,6 +53,18 @@ start_server {tags {"zset"}} { assert_equal 0 [r zcard zdoesntexist] } + test "ZREM removes key after last element is removed" { + r del ztmp + r zadd ztmp 10 x + r zadd ztmp 20 y + + assert_equal 1 [r exists ztmp] + assert_equal 0 [r zrem ztmp z] + assert_equal 1 [r zrem ztmp y] + assert_equal 1 [r zrem ztmp x] + assert_equal 0 [r exists ztmp] + } + test "ZRANGE basics - $encoding" { r del ztmp r zadd ztmp 1 a @@ -244,6 +256,7 @@ start_server {tags {"zset"}} { test "ZREMRANGEBYSCORE basics" { proc remrangebyscore {min max} { create_zset zset {1 a 2 b 3 c 4 d 5 e} + assert_equal 1 [r exists zset] r zremrangebyscore zset $min $max } @@ -290,6 +303,10 @@ start_server {tags {"zset"}} { # exclusive min and max assert_equal 3 [remrangebyscore (1 (5] assert_equal {a e} [r zrange zset 0 -1] + + # destroy when empty + assert_equal 5 [remrangebyscore 1 5] + assert_equal 0 [r exists zset] } test "ZREMRANGEBYSCORE with non-value min or max" { @@ -301,6 +318,7 @@ start_server {tags {"zset"}} { test "ZREMRANGEBYRANK basics" { proc remrangebyrank {min max} { create_zset zset {1 a 2 b 3 c 4 d 5 e} + assert_equal 1 [r exists zset] r zremrangebyrank zset $min $max } @@ -323,6 +341,10 @@ start_server {tags {"zset"}} { # end overflow assert_equal 5 [remrangebyrank 0 10] assert_equal {} [r zrange zset 0 -1] + + # destroy when empty + assert_equal 5 [remrangebyrank 0 4] + assert_equal 0 [r exists zset] } test "ZUNIONSTORE against non-existing key doesn't set destination - $encoding" { @@ -331,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 @@ -436,7 +466,14 @@ start_server {tags {"zset"}} { } basics ziplist - basics raw + basics skiplist + + test {ZINTERSTORE regression with two sets, intset+hashtable} { + r del seta setb setc + r sadd set1 a + r sadd set2 10 + r zinterstore set3 2 set1 set2 + } {0} proc stressers {encoding} { if {$encoding == "ziplist"} { @@ -444,7 +481,7 @@ start_server {tags {"zset"}} { r config set zset-max-ziplist-entries 256 r config set zset-max-ziplist-value 64 set elements 128 - } elseif {$encoding == "raw"} { + } elseif {$encoding == "skiplist"} { r config set zset-max-ziplist-entries 0 r config set zset-max-ziplist-value 0 set elements 1000 @@ -662,6 +699,6 @@ start_server {tags {"zset"}} { tags {"slow"} { stressers ziplist - stressers raw + stressers skiplist } }