zset.tcl (redis-6.2-rc3) | : | zset.tcl (redis-6.2.0) | ||
---|---|---|---|---|

skipping to change at line 1649 | skipping to change at line 1649 | |||

# 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 . | |||

set res [r zrandmember myzset -20] | set res [r zrandmember myzset -20] | |||

assert_equal [llength $res] 20 | assert_equal [llength $res] 20 | |||

set res [r zrandmember myzset -1001] | ||||

assert_equal [llength $res] 1001 | ||||

# 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 | |||

set res [r zrandmember myzset -1001 withscores] | ||||

assert_equal [llength $res] 2002 | ||||

# Test random uniform distribution | ||||

set res [r zrandmember myzset -1000] | ||||

assert_equal [check_histogram_distribution $res 0.05 0.15] true | ||||

# 2) Check that all the elements actually belong to the original zse t. | # 2) Check that all the elements actually belong to the original zse t. | |||

foreach {key val} $res { | foreach {key val} $res { | |||

assert {[dict exists $mydict $key]} | 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 | |||

skipping to change at line 1720 | skipping to change at line 1728 | |||

# 1) Check that all the elements actually belong to the | # 1) Check that all the elements actually belong to the | |||

# original set. | # original set. | |||

foreach ele [dict keys $res] { | foreach ele [dict keys $res] { | |||

assert {[dict exists $mydict $ele]} | 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 | |||

set iterations 1000 | unset -nocomplain allkey | |||

set iterations [expr {1000 / $size}] | ||||

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} { | |||

set res [r zrandmember myzset $size withscores] | set res [r zrandmember myzset $size withscores] | |||

foreach {key value} $res { | foreach {key value} $res { | |||

dict append auxset $key $value | dict append auxset $key $value | |||

lappend allkey $key | ||||

} | } | |||

} else { | } else { | |||

set res [r zrandmember myzset $size] | set res [r zrandmember myzset $size] | |||

foreach key $res { | foreach key $res { | |||

dict append auxset $key | dict append auxset $key | |||

lappend allkey $key | ||||

} | } | |||

} | } | |||

if {[lsort [dict keys $mydict]] eq | if {[lsort [dict keys $mydict]] eq | |||

[lsort [dict keys $auxset]]} { | [lsort [dict keys $auxset]]} { | |||

break; | set all_ele_return true | |||

} | } | |||

} | } | |||

assert {$iterations != 0} | assert_equal $all_ele_return true | |||

assert_equal [check_histogram_distribution $allkey 0.05 0.15] tr | ||||

ue | ||||

} | } | |||

} | } | |||

r config set zset-max-ziplist-value $original_max_value | r config set zset-max-ziplist-value $original_max_value | |||

} | } | |||

} | } | |||

End of changes. 7 change blocks. | ||||

3 lines changed or deleted | | 17 lines changed or added |