"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/unit/type/zset.tcl" between
redis-6.2.4.tar.gz and redis-6.2.5.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

zset.tcl  (redis-6.2.4):zset.tcl  (redis-6.2.5)
skipping to change at line 963 skipping to change at line 963
r del z1 r del z1
create_zset z2 {3 d 4 e 5 f} create_zset z2 {3 d 4 e 5 f}
$rd bzpopmax z1 z2 5 $rd bzpopmax z1 z2 5
assert_equal {z2 f 5} [$rd read] assert_equal {z2 f 5} [$rd read]
$rd bzpopmin z2 z1 5 $rd bzpopmin z2 z1 5
assert_equal {z2 d 3} [$rd read] assert_equal {z2 d 3} [$rd read]
assert_equal 0 [r zcard z1] assert_equal 0 [r zcard z1]
assert_equal 1 [r zcard z2] assert_equal 1 [r zcard z2]
} }
test "Basic ZPOP - $encoding RESP3" {
r hello 3
r del z1
create_zset z1 {0 a 1 b 2 c 3 d}
assert_equal {a 0.0} [r zpopmin z1]
assert_equal {d 3.0} [r zpopmax z1]
r hello 2
}
test "ZPOP with count - $encoding RESP3" {
r hello 3
r del z1
create_zset z1 {0 a 1 b 2 c 3 d}
assert_equal {{a 0.0} {b 1.0}} [r zpopmin z1 2]
assert_equal {{d 3.0} {c 2.0}} [r zpopmax z1 2]
r hello 2
}
test "BZPOP - $encoding RESP3" {
r hello 3
set rd [redis_deferring_client]
create_zset zset {0 a 1 b 2 c}
$rd bzpopmin zset 5
assert_equal {zset a 0} [$rd read]
$rd bzpopmin zset 5
assert_equal {zset b 1} [$rd read]
$rd bzpopmax zset 5
assert_equal {zset c 2} [$rd read]
assert_equal 0 [r exists zset]
r hello 2
}
r config set zset-max-ziplist-entries $original_max_entries r config set zset-max-ziplist-entries $original_max_entries
r config set zset-max-ziplist-value $original_max_value r config set zset-max-ziplist-value $original_max_value
} }
basics ziplist basics ziplist
basics skiplist basics skiplist
test {ZINTERSTORE regression with two sets, intset+hashtable} { test {ZINTERSTORE regression with two sets, intset+hashtable} {
r del seta setb setc r del seta setb setc
r sadd set1 a r sadd set1 a
skipping to change at line 1571 skipping to change at line 1604
test {ZRANGESTORE BYSCORE REV LIMIT} { test {ZRANGESTORE BYSCORE REV LIMIT} {
set res [r zrangestore z2 z1 5 0 BYSCORE REV LIMIT 0 2] set res [r zrangestore z2 z1 5 0 BYSCORE REV LIMIT 0 2]
assert_equal $res 2 assert_equal $res 2
r zrange z2 0 -1 withscores r zrange z2 0 -1 withscores
} {c 3 d 4} } {c 3 d 4}
test {ZRANGE BYSCORE REV LIMIT} { test {ZRANGE BYSCORE REV LIMIT} {
r zrange z1 5 0 BYSCORE REV LIMIT 0 2 WITHSCORES r zrange z1 5 0 BYSCORE REV LIMIT 0 2 WITHSCORES
} {d 4 c 3} } {d 4 c 3}
test {ZRANGESTORE - src key missing} {
set res [r zrangestore z2{t} missing{t} 0 -1]
assert_equal $res 0
r exists z2{t}
} {0}
test {ZRANGESTORE - src key wrong type} {
r zadd z2{t} 1 a
r set foo{t} bar
assert_error "*WRONGTYPE*" {r zrangestore z2{t} foo{t} 0 -1}
r zrange z2{t} 0 -1
} {a}
test {ZRANGESTORE - empty range} { test {ZRANGESTORE - empty range} {
set res [r zrangestore z2 z1 5 6] set res [r zrangestore z2 z1 5 6]
assert_equal $res 0 assert_equal $res 0
r exists z2 r exists z2
} {0} } {0}
test {ZRANGESTORE BYLEX - empty range} { test {ZRANGESTORE BYLEX - empty range} {
set res [r zrangestore z2 z1 \[f \[g BYLEX] set res [r zrangestore z2 z1 \[f \[g BYLEX]
assert_equal $res 0 assert_equal $res 0
r exists z2 r exists z2
skipping to change at line 1619 skipping to change at line 1665
} }
proc get_keys {l} { proc get_keys {l} {
set res {} set res {}
foreach {score key} $l { foreach {score key} $l {
lappend res $key lappend res $key
} }
return $res return $res
} }
# Check whether the zset members belong to the zset
proc check_member {mydict res} {
foreach ele $res {
assert {[dict exists $mydict $ele]}
}
}
# Check whether the zset members and score belong to the zset
proc check_member_and_score {mydict res} {
foreach {key val} $res {
assert_equal $val [dict get $mydict $key]
}
}
foreach {type contents} "ziplist {1 a 2 b 3 c} skiplist {1 a 2 b 3 [randstri ng 70 90 alpha]}" { foreach {type contents} "ziplist {1 a 2 b 3 c} skiplist {1 a 2 b 3 [randstri ng 70 90 alpha]}" {
set original_max_value [lindex [r config get zset-max-ziplist-value] 1] set original_max_value [lindex [r config get zset-max-ziplist-value] 1]
r config set zset-max-ziplist-value 10 r config set zset-max-ziplist-value 10
create_zset myzset $contents create_zset myzset $contents
assert_encoding $type myzset assert_encoding $type myzset
test "ZRANDMEMBER - $type" { test "ZRANDMEMBER - $type" {
unset -nocomplain myzset unset -nocomplain myzset
array set myzset {} array set myzset {}
for {set i 0} {$i < 100} {incr i} { for {set i 0} {$i < 100} {incr i} {
skipping to change at line 1657 skipping to change at line 1717
r hello 2 r hello 2
test "ZRANDMEMBER count of 0 is handled correctly" { test "ZRANDMEMBER count of 0 is handled correctly" {
r zrandmember myzset 0 r zrandmember myzset 0
} {} } {}
test "ZRANDMEMBER with <count> against non existing key" { test "ZRANDMEMBER with <count> against non existing key" {
r zrandmember nonexisting_key 100 r zrandmember nonexisting_key 100
} {} } {}
# Make sure we can distinguish between an empty array and a null response
r readraw 1
test "ZRANDMEMBER count of 0 is handled correctly - emptyarray" {
r zrandmember myzset 0
} {*0}
test "ZRANDMEMBER with <count> against non existing key - emptyarray" {
r zrandmember nonexisting_key 100
} {*0}
r readraw 0
foreach {type contents} " foreach {type contents} "
skiplist {1 a 2 b 3 c 4 d 5 e 6 f 7 g 7 h 9 i 10 [randstring 70 90 alpha ]} skiplist {1 a 2 b 3 c 4 d 5 e 6 f 7 g 7 h 9 i 10 [randstring 70 90 alpha ]}
ziplist {1 a 2 b 3 c 4 d 5 e 6 f 7 g 7 h 9 i 10 j} " { ziplist {1 a 2 b 3 c 4 d 5 e 6 f 7 g 7 h 9 i 10 j} " {
test "ZRANDMEMBER with <count> - $type" { test "ZRANDMEMBER with <count> - $type" {
set original_max_value [lindex [r config get zset-max-ziplist-value] 1] set original_max_value [lindex [r config get zset-max-ziplist-value] 1]
r config set zset-max-ziplist-value 10 r config set zset-max-ziplist-value 10
create_zset myzset $contents create_zset myzset $contents
assert_encoding $type myzset assert_encoding $type myzset
# create a dict for easy lookup # create a dict for easy lookup
skipping to change at line 1679 skipping to change at line 1752
dict append mydict $k $v dict append mydict $k $v
} }
# We'll stress different parts of the code, see the implementation # We'll stress different parts of the code, see the implementation
# of ZRANDMEMBER for more information, but basically there are # of ZRANDMEMBER for more information, but basically there are
# four different code paths. # four different code paths.
# PATH 1: Use negative count. # PATH 1: Use negative count.
# 1) Check that it returns repeated elements with and without values . # 1) Check that it returns repeated elements with and without values .
# 2) Check that all the elements actually belong to the original zse t.
set res [r zrandmember myzset -20] set res [r zrandmember myzset -20]
assert_equal [llength $res] 20 assert_equal [llength $res] 20
check_member $mydict $res
set res [r zrandmember myzset -1001] set res [r zrandmember myzset -1001]
assert_equal [llength $res] 1001 assert_equal [llength $res] 1001
check_member $mydict $res
# again with WITHSCORES # again with WITHSCORES
set res [r zrandmember myzset -20 withscores] set res [r zrandmember myzset -20 withscores]
assert_equal [llength $res] 40 assert_equal [llength $res] 40
check_member_and_score $mydict $res
set res [r zrandmember myzset -1001 withscores] set res [r zrandmember myzset -1001 withscores]
assert_equal [llength $res] 2002 assert_equal [llength $res] 2002
check_member_and_score $mydict $res
# Test random uniform distribution # Test random uniform distribution
# df = 9, 40 means 0.00001 probability # df = 9, 40 means 0.00001 probability
set res [r zrandmember myzset -1000] set res [r zrandmember myzset -1000]
assert_lessthan [chi_square_value $res] 40 assert_lessthan [chi_square_value $res] 40
check_member $mydict $res
# 2) Check that all the elements actually belong to the original zse
t.
foreach {key val} $res {
assert {[dict exists $mydict $key]}
}
# 3) Check that eventually all the elements are returned. # 3) Check that eventually all the elements are returned.
# Use both WITHSCORES and without # Use both WITHSCORES and without
unset -nocomplain auxset unset -nocomplain auxset
set iterations 1000 set iterations 1000
while {$iterations != 0} { while {$iterations != 0} {
incr iterations -1 incr iterations -1
if {[expr {$iterations % 2}] == 0} { if {[expr {$iterations % 2}] == 0} {
set res [r zrandmember myzset -3 withscores] set res [r zrandmember myzset -3 withscores]
foreach {key val} $res { foreach {key val} $res {
dict append auxset $key $val dict append auxset $key $val
} }
} else { } else {
set res [r zrandmember myzset -3] set res [r zrandmember myzset -3]
foreach key $res { foreach key $res {
dict append auxset $key $val dict append auxset $key
} }
} }
if {[lsort [dict keys $mydict]] eq if {[lsort [dict keys $mydict]] eq
[lsort [dict keys $auxset]]} { [lsort [dict keys $auxset]]} {
break; break;
} }
} }
assert {$iterations != 0} assert {$iterations != 0}
# PATH 2: positive count (unique behavior) with requested size # PATH 2: positive count (unique behavior) with requested size
# equal or greater than set size. # equal or greater than set size.
foreach size {10 20} { foreach size {10 20} {
set res [r zrandmember myzset $size] set res [r zrandmember myzset $size]
assert_equal [llength $res] 10 assert_equal [llength $res] 10
assert_equal [lsort $res] [lsort [dict keys $mydict]] assert_equal [lsort $res] [lsort [dict keys $mydict]]
check_member $mydict $res
# again with WITHSCORES # again with WITHSCORES
set res [r zrandmember myzset $size withscores] set res [r zrandmember myzset $size withscores]
assert_equal [llength $res] 20 assert_equal [llength $res] 20
assert_equal [lsort $res] [lsort $mydict] assert_equal [lsort $res] [lsort $mydict]
check_member_and_score $mydict $res
} }
# PATH 3: Ask almost as elements as there are in the set. # PATH 3: Ask almost as elements as there are in the set.
# In this case the implementation will duplicate the original # In this case the implementation will duplicate the original
# set and will remove random elements up to the requested size. # set and will remove random elements up to the requested size.
# #
# PATH 4: Ask a number of elements definitely smaller than # PATH 4: Ask a number of elements definitely smaller than
# the set size. # the set size.
# #
# We can test both the code paths just changing the size but # We can test both the code paths just changing the size but
# using the same code. # using the same code.
foreach size {8 2} { foreach size {1 2 8} {
# 1) Check that all the elements actually belong to the
# original set.
set res [r zrandmember myzset $size] set res [r zrandmember myzset $size]
assert_equal [llength $res] $size assert_equal [llength $res] $size
check_member $mydict $res
# again with WITHSCORES # again with WITHSCORES
set res [r zrandmember myzset $size withscores] set res [r zrandmember myzset $size withscores]
assert_equal [llength $res] [expr {$size * 2}] assert_equal [llength $res] [expr {$size * 2}]
check_member_and_score $mydict $res
# 1) Check that all the elements actually belong to the
# original set.
foreach ele [dict keys $res] {
assert {[dict exists $mydict $ele]}
}
# 2) Check that eventually all the elements are returned. # 2) Check that eventually all the elements are returned.
# Use both WITHSCORES and without # Use both WITHSCORES and without
unset -nocomplain auxset unset -nocomplain auxset
unset -nocomplain allkey unset -nocomplain allkey
set iterations [expr {1000 / $size}] set iterations [expr {1000 / $size}]
set all_ele_return false set all_ele_return false
while {$iterations != 0} { while {$iterations != 0} {
incr iterations -1 incr iterations -1
if {[expr {$iterations % 2}] == 0} { if {[expr {$iterations % 2}] == 0} {
 End of changes. 16 change blocks. 
14 lines changed or deleted 91 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)