1 start_server
{tags
{"zset"}} {
2 test
{ZSET basic ZADD and score
update} {
6 set aux1
[r zrange ztmp
0 -1]
8 set aux2
[r zrange ztmp
0 -1]
16 test
{ZCARD non existing key
} {
24 list [r zrank zranktmp x
] [r zrank zranktmp y
] [r zrank zranktmp z
]
27 test
{ZREVRANK basics
} {
28 list [r zrevrank zranktmp x
] [r zrevrank zranktmp y
] [r zrevrank zranktmp z
]
31 test
{ZRANK
- after deletion
} {
33 list [r zrank zranktmp x
] [r zrank zranktmp z
]
39 for {set i
0} {$i < 1000} {incr i
} {
40 set score
[expr rand
()]
42 r zadd zscoretest
$score $i
44 for {set i
0} {$i < 1000} {incr i
} {
45 if {[r zscore zscoretest
$i] != [lindex $aux $i]} {
46 set err
"Expected score was [lindex $aux $i] but got [r zscore zscoretest $i] for element $i"
53 test
{ZSCORE
after a DEBUG RELOAD
} {
57 for {set i
0} {$i < 1000} {incr i
} {
58 set score
[expr rand
()]
60 r zadd zscoretest
$score $i
63 for {set i
0} {$i < 1000} {incr i
} {
64 if {[r zscore zscoretest
$i] != [lindex $aux $i]} {
65 set err
"Expected score was [lindex $aux $i] but got [r zscore zscoretest $i] for element $i"
72 test
{ZRANGE and ZREVRANGE basics
} {
73 list [r zrange ztmp
0 -1] [r zrevrange ztmp
0 -1] \
74 [r zrange ztmp
1 -1] [r zrevrange ztmp
1 -1]
75 } {{y x z
} {z x y
} {x z
} {x y
}}
77 test
{ZRANGE WITHSCORES
} {
78 r zrange ztmp
0 -1 withscores
81 test
{ZSETs stress tester
- sorting is working well?
} {
83 for {set test
0} {$test < 2} {incr test
} {
84 unset -nocomplain auxarray
88 for {set i
0} {$i < 1000} {incr i
} {
90 set score
[expr rand
()]
92 set score
[expr int
(rand
()*10)]
94 set auxarray
($i) $score
95 r zadd myzset
$score $i
97 if {[expr rand
()] < .2} {
98 set j
[expr int
(rand
()*1000)]
100 set score
[expr rand
()]
102 set score
[expr int
(rand
()*10)]
104 set auxarray
($j) $score
105 r zadd myzset
$score $j
108 foreach {item score
} [array get auxarray
] {
109 lappend auxlist
[list $score $item]
111 set sorted
[lsort -command zlistAlikeSort
$auxlist]
114 lappend auxlist
[lindex $x 1]
116 set fromredis
[r zrange myzset
0 -1]
118 for {set i
0} {$i < [llength $fromredis]} {incr i
} {
119 if {[lindex $fromredis $i] != [lindex $auxlist $i]} {
127 test
{ZINCRBY
- can create a new sorted
set} {
130 list [r zrange zset
0 -1] [r zscore zset foo
]
133 test
{ZINCRBY
- increment and decrement
} {
136 set v1
[r zrange zset
0 -1]
137 r zincrby zset
10 bar
138 r zincrby zset
-5 foo
139 r zincrby zset
-5 bar
140 set v2
[r zrange zset
0 -1]
141 list $v1 $v2 [r zscore zset foo
] [r zscore zset bar
]
142 } {{bar foo
} {foo bar
} -2 6}
144 test
{ZRANGEBYSCORE and ZCOUNT basics
} {
151 list [r zrangebyscore zset
2 4] [r zrangebyscore zset
(2 (4] \
152 [r zcount zset
2 4] [r zcount zset
(2 (4]
155 test
{ZRANGEBYSCORE withscores
} {
162 r zrangebyscore zset
2 4 withscores
166 test
{ZRANGEBYSCORE fuzzy test
, 100 ranges in
1000 elements sorted
set} {
169 for {set i
0} {$i < 1000} {incr i
} {
170 r zadd zset
[expr rand
()] $i
172 for {set i
0} {$i < 100} {incr i
} {
173 set min
[expr rand
()]
174 set max
[expr rand
()]
180 set low
[r zrangebyscore zset
-inf $min]
181 set ok
[r zrangebyscore zset
$min $max]
182 set high
[r zrangebyscore zset
$max +inf
]
183 set lowx
[r zrangebyscore zset
-inf ($min]
184 set okx
[r zrangebyscore zset
($min ($max]
185 set highx
[r zrangebyscore zset
($max +inf
]
187 if {[r zcount zset
-inf $min] != [llength $low]} {
188 append err
"Error, len does not match zcount\n"
190 if {[r zcount zset
$min $max] != [llength $ok]} {
191 append err
"Error, len does not match zcount\n"
193 if {[r zcount zset
$max +inf
] != [llength $high]} {
194 append err
"Error, len does not match zcount\n"
196 if {[r zcount zset
-inf ($min] != [llength $lowx]} {
197 append err
"Error, len does not match zcount\n"
199 if {[r zcount zset
($min ($max] != [llength $okx]} {
200 append err
"Error, len does not match zcount\n"
202 if {[r zcount zset
($max +inf
] != [llength $highx]} {
203 append err
"Error, len does not match zcount\n"
207 set score
[r zscore zset
$x]
209 append err
"Error, score for $x is $score > $min\n"
213 set score
[r zscore zset
$x]
214 if {$score >= $min} {
215 append err
"Error, score for $x is $score >= $min\n"
219 set score
[r zscore zset
$x]
220 if {$score < $min ||
$score > $max} {
221 append err
"Error, score for $x is $score outside $min-$max range\n"
225 set score
[r zscore zset
$x]
226 if {$score <= $min ||
$score >= $max} {
227 append err
"Error, score for $x is $score outside $min-$max open range\n"
231 set score
[r zscore zset
$x]
233 append err
"Error, score for $x is $score < $max\n"
237 set score
[r zscore zset
$x]
238 if {$score <= $max} {
239 append err
"Error, score for $x is $score <= $max\n"
247 test
{ZRANGEBYSCORE with LIMIT
} {
255 [r zrangebyscore zset
0 10 LIMIT
0 2] \
256 [r zrangebyscore zset
0 10 LIMIT
2 3] \
257 [r zrangebyscore zset
0 10 LIMIT
2 10] \
258 [r zrangebyscore zset
0 10 LIMIT
20 10]
259 } {{a b
} {c d e
} {c d e
} {}}
261 test
{ZRANGEBYSCORE with LIMIT and withscores
} {
268 r zrangebyscore zset
20 50 LIMIT
2 3 withscores
271 test
{ZREMRANGEBYSCORE basics
} {
278 list [r zremrangebyscore zset
2 4] [r zrange zset
0 -1]
281 test
{ZREMRANGEBYSCORE from
-inf to
+inf
} {
288 list [r zremrangebyscore zset
-inf +inf
] [r zrange zset
0 -1]
291 test
{ZREMRANGEBYRANK basics
} {
298 list [r zremrangebyrank zset
1 3] [r zrange zset
0 -1]
301 test
{ZUNIONSTORE against non-existing key doesn't
set destination
} {
303 list [r zunionstore dst_key
1 zseta
] [r exists dst_key
]
306 test
{ZUNIONSTORE basics
} {
307 r del zseta zsetb zsetc
314 list [r zunionstore zsetc
2 zseta zsetb
] [r zrange zsetc
0 -1 withscores
]
315 } {4 {a
1 b
3 d
3 c
5}}
317 test
{ZUNIONSTORE with weights
} {
318 list [r zunionstore zsetc
2 zseta zsetb weights
2 3] [r zrange zsetc
0 -1 withscores
]
319 } {4 {a
2 b
7 d
9 c
12}}
321 test
{ZUNIONSTORE with a regular
set and weights
} {
326 list [r zunionstore zsetc
2 seta zsetb weights
2 3] [r zrange zsetc
0 -1 withscores
]
327 } {4 {a
2 b
5 c
8 d
9}}
329 test
{ZUNIONSTORE with AGGREGATE MIN
} {
330 list [r zunionstore zsetc
2 zseta zsetb aggregate min
] [r zrange zsetc
0 -1 withscores
]
331 } {4 {a
1 b
1 c
2 d
3}}
333 test
{ZUNIONSTORE with AGGREGATE MAX
} {
334 list [r zunionstore zsetc
2 zseta zsetb aggregate max
] [r zrange zsetc
0 -1 withscores
]
335 } {4 {a
1 b
2 c
3 d
3}}
337 test
{ZINTERSTORE basics
} {
338 list [r zinterstore zsetc
2 zseta zsetb
] [r zrange zsetc
0 -1 withscores
]
341 test
{ZINTERSTORE with weights
} {
342 list [r zinterstore zsetc
2 zseta zsetb weights
2 3] [r zrange zsetc
0 -1 withscores
]
345 test
{ZINTERSTORE with a regular
set and weights
} {
350 list [r zinterstore zsetc
2 seta zsetb weights
2 3] [r zrange zsetc
0 -1 withscores
]
353 test
{ZINTERSTORE with AGGREGATE MIN
} {
354 list [r zinterstore zsetc
2 zseta zsetb aggregate min
] [r zrange zsetc
0 -1 withscores
]
357 test
{ZINTERSTORE with AGGREGATE MAX
} {
358 list [r zinterstore zsetc
2 zseta zsetb aggregate max
] [r zrange zsetc
0 -1 withscores
]
362 test
{ZSETs skiplist implementation backlink consistency test
} {
365 for {set j
0} {$j < $elements} {incr j
} {
366 r zadd myzset
[expr rand
()] "Element-$j"
367 r zrem myzset
"Element-[expr int(rand()*$elements)]"
369 set l1
[r zrange myzset
0 -1]
370 set l2
[r zrevrange myzset
0 -1]
371 for {set j
0} {$j < [llength $l1]} {incr j
} {
372 if {[lindex $l1 $j] ne
[lindex $l2 end-
$j]} {
379 test
{ZSETs ZRANK augmented skip
list stress testing
} {
382 for {set k
0} {$k < 10000} {incr k
} {
383 set i
[expr {$k%1000}]
384 if {[expr rand
()] < .2} {
387 set score
[expr rand
()]
388 r zadd myzset
$score $i
390 set card
[r zcard myzset
]
392 set index
[randomInt
$card]
393 set ele
[lindex [r zrange myzset
$index $index] 0]
394 set rank
[r zrank myzset
$ele]
395 if {$rank != $index} {
396 set err
"$ele RANK is wrong! ($rank != $index)"
405 test
{ZSET element can't be
set to nan with ZADD
} {
407 catch {r zadd myzset nan abc
} e
411 test
{ZSET element can't be
set to nan with ZINCRBY
} {
413 catch {r zincrby myzset nan abc
} e
417 test
{ZINCRBY calls leading to Nan are refused
} {
419 r zincrby myzset
+inf abc
420 catch {r zincrby myzset
-inf abc
} e