summaryrefslogtreecommitdiff
path: root/tests/unit/type
diff options
context:
space:
mode:
authorJonah H. Harris <jonah.harris@gmail.com>2021-08-03 04:45:27 -0400
committerGitHub <noreply@github.com>2021-08-03 11:45:27 +0300
commit432c92d8df179a6a1aeae2df553c6b3fc810be76 (patch)
tree7fb64e93ee532ebe6f508c68f8f108b68a6606dd /tests/unit/type
parentbdbf5eedae55a1eea869cc5a31832d0c35113c66 (diff)
downloadredis-432c92d8df179a6a1aeae2df553c6b3fc810be76.tar.gz
Add SINTERCARD/ZINTERCARD Commands (#8946)
Add SINTERCARD and ZINTERCARD commands that are similar to ZINTER and SINTER but only return the cardinality with minimum processing and memory overheads. Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'tests/unit/type')
-rw-r--r--tests/unit/type/set.tcl12
-rw-r--r--tests/unit/type/zset.tcl13
2 files changed, 22 insertions, 3 deletions
diff --git a/tests/unit/type/set.tcl b/tests/unit/type/set.tcl
index 463dc5859..9c512726d 100644
--- a/tests/unit/type/set.tcl
+++ b/tests/unit/type/set.tcl
@@ -143,6 +143,10 @@ start_server {
r srem myset 1 2 3 4 5 6 7 8
} {3}
+ test "SINTERCARD against non-existing key" {
+ assert_equal 0 [r sintercard non-existing-key]
+ }
+
foreach {type} {hashtable intset} {
for {set i 1} {$i <= 5} {incr i} {
r del [format "set%d{t}" $i]
@@ -182,6 +186,10 @@ start_server {
assert_equal [list 195 196 197 198 199 $large] [lsort [r sinter set1{t} set2{t}]]
}
+ test "SINTERCARD with two sets - $type" {
+ assert_equal 6 [r sintercard set1{t} set2{t}]
+ }
+
test "SINTERSTORE with two sets - $type" {
r sinterstore setres{t} set1{t} set2{t}
assert_encoding $type setres{t}
@@ -211,6 +219,10 @@ start_server {
assert_equal [list 195 199 $large] [lsort [r sinter set1{t} set2{t} set3{t}]]
}
+ test "SINTERCARD against three sets - $type" {
+ assert_equal 3 [r sintercard set1{t} set2{t} set3{t}]
+ }
+
test "SINTERSTORE with three sets - $type" {
r sinterstore setres{t} set1{t} set2{t} set3{t}
assert_equal [list 195 199 $large] [lsort [r smembers setres{t}]]
diff --git a/tests/unit/type/zset.tcl b/tests/unit/type/zset.tcl
index 1f2f00576..75d51bb2e 100644
--- a/tests/unit/type/zset.tcl
+++ b/tests/unit/type/zset.tcl
@@ -647,10 +647,11 @@ start_server {tags {"zset"}} {
assert_equal 0 [r exists dst_key{t}]
}
- test "ZUNION/ZINTER/ZDIFF against non-existing key - $encoding" {
+ test "ZUNION/ZINTER/ZINTERCARD/ZDIFF against non-existing key - $encoding" {
r del zseta
assert_equal {} [r zunion 1 zseta]
assert_equal {} [r zinter 1 zseta]
+ assert_equal 0 [r zintercard 1 zseta]
assert_equal {} [r zdiff 1 zseta]
}
@@ -662,12 +663,13 @@ start_server {tags {"zset"}} {
r zrange zsetc{t} 0 -1 withscores
} {a 1 b 2}
- test "ZUNION/ZINTER/ZDIFF with empty set - $encoding" {
+ test "ZUNION/ZINTER/ZINTERCARD/ZDIFF with empty set - $encoding" {
r del zseta{t} zsetb{t}
r zadd zseta{t} 1 a
r zadd zseta{t} 2 b
assert_equal {a 1 b 2} [r zunion 2 zseta{t} zsetb{t} withscores]
assert_equal {} [r zinter 2 zseta{t} zsetb{t} withscores]
+ assert_equal 0 [r zintercard 2 zseta{t} zsetb{t}]
assert_equal {a 1 b 2} [r zdiff 2 zseta{t} zsetb{t} withscores]
}
@@ -684,7 +686,7 @@ start_server {tags {"zset"}} {
assert_equal {a 1 b 3 d 3 c 5} [r zrange zsetc{t} 0 -1 withscores]
}
- test "ZUNION/ZINTER/ZDIFF with integer members - $encoding" {
+ test "ZUNION/ZINTER/ZINTERCARD/ZDIFF with integer members - $encoding" {
r del zsetd{t} zsetf{t}
r zadd zsetd{t} 1 1
r zadd zsetd{t} 2 2
@@ -695,6 +697,7 @@ start_server {tags {"zset"}} {
assert_equal {1 2 2 2 4 4 3 6} [r zunion 2 zsetd{t} zsetf{t} withscores]
assert_equal {1 2 3 6} [r zinter 2 zsetd{t} zsetf{t} withscores]
+ assert_equal 2 [r zintercard 2 zsetd{t} zsetf{t}]
assert_equal {2 2} [r zdiff 2 zsetd{t} zsetf{t} withscores]
}
@@ -747,6 +750,10 @@ start_server {tags {"zset"}} {
assert_equal {b 3 c 5} [r zinter 2 zseta{t} zsetb{t} withscores]
}
+ test "ZINTERCARD basics - $encoding" {
+ assert_equal 2 [r zintercard 2 zseta{t} zsetb{t}]
+ }
+
test "ZINTER RESP3 - $encoding" {
r hello 3
assert_equal {{b 3.0} {c 5.0}} [r zinter 2 zseta{t} zsetb{t} withscores]