1 start_server
{tags
{"zset"}} {
2 proc create_zset
{key items
} {
4 foreach {score
entry} $items {
5 r zadd
$key $score $entry
9 proc basics
{encoding} {
10 if {$encoding == "ziplist"} {
11 r config
set zset-max-ziplist-entries
128
12 r config
set zset-max-ziplist-value
64
13 } elseif
{$encoding == "skiplist"} {
14 r config
set zset-max-ziplist-entries
0
15 r config
set zset-max-ziplist-value
0
17 puts "Unknown sorted set encoding"
21 test
"Check encoding - $encoding" {
24 assert_encoding
$encoding ztmp
27 test
"ZSET basic ZADD and score update - $encoding" {
32 assert_equal
{x y z
} [r zrange ztmp
0 -1]
35 assert_equal
{y x z
} [r zrange ztmp
0 -1]
38 test
"ZSET element can't be set to NaN with ZADD - $encoding" {
39 assert_error
"*not*float*" {r zadd myzset nan abc
}
42 test
"ZSET element can't be set to NaN with ZINCRBY" {
43 assert_error
"*not*float*" {r zadd myzset nan abc
}
46 test
"ZINCRBY calls leading to NaN result in error" {
47 r zincrby myzset
+inf abc
48 assert_error
"*NaN*" {r zincrby myzset
-inf abc
}
51 test
{ZADD
- Variadic version base case
} {
53 list [r zadd myzset
10 a
20 b
30 c
] [r zrange myzset
0 -1 withscores
]
54 } {3 {a
10 b
20 c
30}}
56 test
{ZADD
- Return value is the number of actually added items
} {
57 list [r zadd myzset
5 x
20 b
30 c
] [r zrange myzset
0 -1 withscores
]
58 } {1 {x
5 a
10 b
20 c
30}}
60 test
{ZADD
- Variadic version does not add nothing on single parsing err
} {
62 catch {r zadd myzset
10 a
20 b
30.badscore c
} e
63 assert_match
{*ERR
*not
*float
*} $e
67 test
{ZADD
- Variadic version will
raise error on missing arg
} {
69 catch {r zadd myzset
10 a
20 b
30 c
40} e
70 assert_match
{*ERR
*syntax
*} $e
73 test
{ZINCRBY does not work variadic even
if shares ZADD implementation
} {
75 catch {r zincrby myzset
10 a
20 b
30 c
} e
76 assert_match
{*ERR
*wrong
*number
*arg
*} $e
79 test
"ZCARD basics - $encoding" {
80 assert_equal
3 [r zcard ztmp
]
81 assert_equal
0 [r zcard zdoesntexist
]
84 test
"ZREM removes key after last element is removed" {
89 assert_equal
1 [r exists ztmp
]
90 assert_equal
0 [r zrem ztmp z
]
91 assert_equal
1 [r zrem ztmp y
]
92 assert_equal
1 [r zrem ztmp x
]
93 assert_equal
0 [r exists ztmp
]
96 test
"ZREM variadic version" {
98 r zadd ztmp
10 a
20 b
30 c
99 assert_equal
2 [r zrem ztmp x y a b k
]
100 assert_equal
0 [r zrem ztmp foo bar
]
101 assert_equal
1 [r zrem ztmp c
]
105 test
"ZREM variadic version -- remove elements after key deletion" {
107 r zadd ztmp
10 a
20 b
30 c
108 r zrem ztmp a b c d e f g
111 test
"ZRANGE basics - $encoding" {
118 assert_equal
{a b c d
} [r zrange ztmp
0 -1]
119 assert_equal
{a b c
} [r zrange ztmp
0 -2]
120 assert_equal
{b c d
} [r zrange ztmp
1 -1]
121 assert_equal
{b c
} [r zrange ztmp
1 -2]
122 assert_equal
{c d
} [r zrange ztmp
-2 -1]
123 assert_equal
{c
} [r zrange ztmp
-2 -2]
125 # out of range start index
126 assert_equal
{a b c
} [r zrange ztmp
-5 2]
127 assert_equal
{a b
} [r zrange ztmp
-5 1]
128 assert_equal
{} [r zrange ztmp
5 -1]
129 assert_equal
{} [r zrange ztmp
5 -2]
131 # out of range end index
132 assert_equal
{a b c d
} [r zrange ztmp
0 5]
133 assert_equal
{b c d
} [r zrange ztmp
1 5]
134 assert_equal
{} [r zrange ztmp
0 -5]
135 assert_equal
{} [r zrange ztmp
1 -5]
138 assert_equal
{a
1 b
2 c
3 d
4} [r zrange ztmp
0 -1 withscores
]
141 test
"ZREVRANGE basics - $encoding" {
148 assert_equal
{d c b a
} [r zrevrange ztmp
0 -1]
149 assert_equal
{d c b
} [r zrevrange ztmp
0 -2]
150 assert_equal
{c b a
} [r zrevrange ztmp
1 -1]
151 assert_equal
{c b
} [r zrevrange ztmp
1 -2]
152 assert_equal
{b a
} [r zrevrange ztmp
-2 -1]
153 assert_equal
{b
} [r zrevrange ztmp
-2 -2]
155 # out of range start index
156 assert_equal
{d c b
} [r zrevrange ztmp
-5 2]
157 assert_equal
{d c
} [r zrevrange ztmp
-5 1]
158 assert_equal
{} [r zrevrange ztmp
5 -1]
159 assert_equal
{} [r zrevrange ztmp
5 -2]
161 # out of range end index
162 assert_equal
{d c b a
} [r zrevrange ztmp
0 5]
163 assert_equal
{c b a
} [r zrevrange ztmp
1 5]
164 assert_equal
{} [r zrevrange ztmp
0 -5]
165 assert_equal
{} [r zrevrange ztmp
1 -5]
168 assert_equal
{d
4 c
3 b
2 a
1} [r zrevrange ztmp
0 -1 withscores
]
171 test
"ZRANK/ZREVRANK basics - $encoding" {
176 assert_equal
0 [r zrank zranktmp x
]
177 assert_equal
1 [r zrank zranktmp y
]
178 assert_equal
2 [r zrank zranktmp z
]
179 assert_equal
"" [r zrank zranktmp foo
]
180 assert_equal
2 [r zrevrank zranktmp x
]
181 assert_equal
1 [r zrevrank zranktmp y
]
182 assert_equal
0 [r zrevrank zranktmp z
]
183 assert_equal
"" [r zrevrank zranktmp foo
]
186 test
"ZRANK - after deletion - $encoding" {
188 assert_equal
0 [r zrank zranktmp x
]
189 assert_equal
1 [r zrank zranktmp z
]
192 test
"ZINCRBY - can create a new sorted set - $encoding" {
195 assert_equal
{foo
} [r zrange zset
0 -1]
196 assert_equal
1 [r zscore zset foo
]
199 test
"ZINCRBY - increment and decrement - $encoding" {
202 assert_equal
{bar foo
} [r zrange zset
0 -1]
204 r zincrby zset
10 bar
205 r zincrby zset
-5 foo
206 r zincrby zset
-5 bar
207 assert_equal
{foo bar
} [r zrange zset
0 -1]
209 assert_equal
-2 [r zscore zset foo
]
210 assert_equal
6 [r zscore zset bar
]
213 proc create_default_zset
{} {
214 create_zset zset
{-inf a
1 b
2 c
3 d
4 e
5 f
+inf g
}
217 test
"ZRANGEBYSCORE/ZREVRANGEBYSCORE/ZCOUNT basics" {
221 assert_equal
{a b c
} [r zrangebyscore zset
-inf 2]
222 assert_equal
{b c d
} [r zrangebyscore zset
0 3]
223 assert_equal
{d e f
} [r zrangebyscore zset
3 6]
224 assert_equal
{e f g
} [r zrangebyscore zset
4 +inf
]
225 assert_equal
{c b a
} [r zrevrangebyscore zset
2 -inf]
226 assert_equal
{d c b
} [r zrevrangebyscore zset
3 0]
227 assert_equal
{f e d
} [r zrevrangebyscore zset
6 3]
228 assert_equal
{g f e
} [r zrevrangebyscore zset
+inf
4]
229 assert_equal
3 [r zcount zset
0 3]
232 assert_equal
{b
} [r zrangebyscore zset
(-inf (2]
233 assert_equal
{b c
} [r zrangebyscore zset
(0 (3]
234 assert_equal
{e f
} [r zrangebyscore zset
(3 (6]
235 assert_equal
{f
} [r zrangebyscore zset
(4 (+inf
]
236 assert_equal
{b
} [r zrevrangebyscore zset
(2 (-inf]
237 assert_equal
{c b
} [r zrevrangebyscore zset
(3 (0]
238 assert_equal
{f e
} [r zrevrangebyscore zset
(6 (3]
239 assert_equal
{f
} [r zrevrangebyscore zset
(+inf
(4]
240 assert_equal
2 [r zcount zset
(0 (3]
247 assert_equal
{} [r zrangebyscore zset
4 2]
248 assert_equal
{} [r zrangebyscore zset
6 +inf
]
249 assert_equal
{} [r zrangebyscore zset
-inf -6]
250 assert_equal
{} [r zrevrangebyscore zset
+inf
6]
251 assert_equal
{} [r zrevrangebyscore zset
-6 -inf]
254 assert_equal
{} [r zrangebyscore zset
(4 (2]
255 assert_equal
{} [r zrangebyscore zset
2 (2]
256 assert_equal
{} [r zrangebyscore zset
(2 2]
257 assert_equal
{} [r zrangebyscore zset
(6 (+inf
]
258 assert_equal
{} [r zrangebyscore zset
(-inf (-6]
259 assert_equal
{} [r zrevrangebyscore zset
(+inf
(6]
260 assert_equal
{} [r zrevrangebyscore zset
(-6 (-inf]
263 assert_equal
{} [r zrangebyscore zset
2.4 2.6]
264 assert_equal
{} [r zrangebyscore zset
(2.4 2.6]
265 assert_equal
{} [r zrangebyscore zset
2.4 (2.6]
266 assert_equal
{} [r zrangebyscore zset
(2.4 (2.6]
269 test
"ZRANGEBYSCORE with WITHSCORES" {
271 assert_equal
{b
1 c
2 d
3} [r zrangebyscore zset
0 3 withscores
]
272 assert_equal
{d
3 c
2 b
1} [r zrevrangebyscore zset
3 0 withscores
]
275 test
"ZRANGEBYSCORE with LIMIT" {
277 assert_equal
{b c
} [r zrangebyscore zset
0 10 LIMIT
0 2]
278 assert_equal
{d e f
} [r zrangebyscore zset
0 10 LIMIT
2 3]
279 assert_equal
{d e f
} [r zrangebyscore zset
0 10 LIMIT
2 10]
280 assert_equal
{} [r zrangebyscore zset
0 10 LIMIT
20 10]
281 assert_equal
{f e
} [r zrevrangebyscore zset
10 0 LIMIT
0 2]
282 assert_equal
{d c b
} [r zrevrangebyscore zset
10 0 LIMIT
2 3]
283 assert_equal
{d c b
} [r zrevrangebyscore zset
10 0 LIMIT
2 10]
284 assert_equal
{} [r zrevrangebyscore zset
10 0 LIMIT
20 10]
287 test
"ZRANGEBYSCORE with LIMIT and WITHSCORES" {
289 assert_equal
{e
4 f
5} [r zrangebyscore zset
2 5 LIMIT
2 3 WITHSCORES
]
290 assert_equal
{d
3 c
2} [r zrevrangebyscore zset
5 2 LIMIT
2 3 WITHSCORES
]
293 test
"ZRANGEBYSCORE with non-value min or max" {
294 assert_error
"*not*float*" {r zrangebyscore fooz str
1}
295 assert_error
"*not*float*" {r zrangebyscore fooz
1 str
}
296 assert_error
"*not*float*" {r zrangebyscore fooz
1 NaN
}
299 test
"ZREMRANGEBYSCORE basics" {
300 proc remrangebyscore
{min max
} {
301 create_zset zset
{1 a
2 b
3 c
4 d
5 e
}
302 assert_equal
1 [r exists zset
]
303 r zremrangebyscore zset
$min $max
307 assert_equal
3 [remrangebyscore
2 4]
308 assert_equal
{a e
} [r zrange zset
0 -1]
311 assert_equal
1 [remrangebyscore
-10 1]
312 assert_equal
{b c d e
} [r zrange zset
0 -1]
315 assert_equal
1 [remrangebyscore
5 10]
316 assert_equal
{a b c d
} [r zrange zset
0 -1]
319 assert_equal
0 [remrangebyscore
4 2]
320 assert_equal
{a b c d e
} [r zrange zset
0 -1]
323 assert_equal
3 [remrangebyscore
-inf 3]
324 assert_equal
{d e
} [r zrange zset
0 -1]
327 assert_equal
3 [remrangebyscore
3 +inf
]
328 assert_equal
{a b
} [r zrange zset
0 -1]
331 assert_equal
5 [remrangebyscore
-inf +inf
]
332 assert_equal
{} [r zrange zset
0 -1]
335 assert_equal
4 [remrangebyscore
(1 5]
336 assert_equal
{a
} [r zrange zset
0 -1]
337 assert_equal
3 [remrangebyscore
(2 5]
338 assert_equal
{a b
} [r zrange zset
0 -1]
341 assert_equal
4 [remrangebyscore
1 (5]
342 assert_equal
{e
} [r zrange zset
0 -1]
343 assert_equal
3 [remrangebyscore
1 (4]
344 assert_equal
{d e
} [r zrange zset
0 -1]
346 # exclusive min and max
347 assert_equal
3 [remrangebyscore
(1 (5]
348 assert_equal
{a e
} [r zrange zset
0 -1]
351 assert_equal
5 [remrangebyscore
1 5]
352 assert_equal
0 [r exists zset
]
355 test
"ZREMRANGEBYSCORE with non-value min or max" {
356 assert_error
"*not*float*" {r zremrangebyscore fooz str
1}
357 assert_error
"*not*float*" {r zremrangebyscore fooz
1 str
}
358 assert_error
"*not*float*" {r zremrangebyscore fooz
1 NaN
}
361 test
"ZREMRANGEBYRANK basics" {
362 proc remrangebyrank
{min max
} {
363 create_zset zset
{1 a
2 b
3 c
4 d
5 e
}
364 assert_equal
1 [r exists zset
]
365 r zremrangebyrank zset
$min $max
369 assert_equal
3 [remrangebyrank
1 3]
370 assert_equal
{a e
} [r zrange zset
0 -1]
373 assert_equal
1 [remrangebyrank
-10 0]
374 assert_equal
{b c d e
} [r zrange zset
0 -1]
377 assert_equal
0 [remrangebyrank
10 -1]
378 assert_equal
{a b c d e
} [r zrange zset
0 -1]
381 assert_equal
0 [remrangebyrank
0 -10]
382 assert_equal
{a b c d e
} [r zrange zset
0 -1]
385 assert_equal
5 [remrangebyrank
0 10]
386 assert_equal
{} [r zrange zset
0 -1]
389 assert_equal
5 [remrangebyrank
0 4]
390 assert_equal
0 [r exists zset
]
393 test
"ZUNIONSTORE against non-existing key doesn't set destination - $encoding" {
395 assert_equal
0 [r zunionstore dst_key
1 zseta
]
396 assert_equal
0 [r exists dst_key
]
399 test
"ZUNIONSTORE with empty set - $encoding" {
403 r zunionstore zsetc
2 zseta zsetb
404 r zrange zsetc
0 -1 withscores
407 test
"ZUNIONSTORE basics - $encoding" {
408 r del zseta zsetb zsetc
416 assert_equal
4 [r zunionstore zsetc
2 zseta zsetb
]
417 assert_equal
{a
1 b
3 d
3 c
5} [r zrange zsetc
0 -1 withscores
]
420 test
"ZUNIONSTORE with weights - $encoding" {
421 assert_equal
4 [r zunionstore zsetc
2 zseta zsetb weights
2 3]
422 assert_equal
{a
2 b
7 d
9 c
12} [r zrange zsetc
0 -1 withscores
]
425 test
"ZUNIONSTORE with a regular set and weights - $encoding" {
431 assert_equal
4 [r zunionstore zsetc
2 seta zsetb weights
2 3]
432 assert_equal
{a
2 b
5 c
8 d
9} [r zrange zsetc
0 -1 withscores
]
435 test
"ZUNIONSTORE with AGGREGATE MIN - $encoding" {
436 assert_equal
4 [r zunionstore zsetc
2 zseta zsetb aggregate min
]
437 assert_equal
{a
1 b
1 c
2 d
3} [r zrange zsetc
0 -1 withscores
]
440 test
"ZUNIONSTORE with AGGREGATE MAX - $encoding" {
441 assert_equal
4 [r zunionstore zsetc
2 zseta zsetb aggregate max
]
442 assert_equal
{a
1 b
2 c
3 d
3} [r zrange zsetc
0 -1 withscores
]
445 test
"ZINTERSTORE basics - $encoding" {
446 assert_equal
2 [r zinterstore zsetc
2 zseta zsetb
]
447 assert_equal
{b
3 c
5} [r zrange zsetc
0 -1 withscores
]
450 test
"ZINTERSTORE with weights - $encoding" {
451 assert_equal
2 [r zinterstore zsetc
2 zseta zsetb weights
2 3]
452 assert_equal
{b
7 c
12} [r zrange zsetc
0 -1 withscores
]
455 test
"ZINTERSTORE with a regular set and weights - $encoding" {
460 assert_equal
2 [r zinterstore zsetc
2 seta zsetb weights
2 3]
461 assert_equal
{b
5 c
8} [r zrange zsetc
0 -1 withscores
]
464 test
"ZINTERSTORE with AGGREGATE MIN - $encoding" {
465 assert_equal
2 [r zinterstore zsetc
2 zseta zsetb aggregate min
]
466 assert_equal
{b
1 c
2} [r zrange zsetc
0 -1 withscores
]
469 test
"ZINTERSTORE with AGGREGATE MAX - $encoding" {
470 assert_equal
2 [r zinterstore zsetc
2 zseta zsetb aggregate max
]
471 assert_equal
{b
2 c
3} [r zrange zsetc
0 -1 withscores
]
474 foreach cmd
{ZUNIONSTORE ZINTERSTORE
} {
475 test
"$cmd with +inf/-inf scores - $encoding" {
476 r del zsetinf1 zsetinf2
478 r zadd zsetinf1
+inf key
479 r zadd zsetinf2
+inf key
480 r
$cmd zsetinf3
2 zsetinf1 zsetinf2
481 assert_equal inf
[r zscore zsetinf3 key
]
483 r zadd zsetinf1
-inf key
484 r zadd zsetinf2
+inf key
485 r
$cmd zsetinf3
2 zsetinf1 zsetinf2
486 assert_equal
0 [r zscore zsetinf3 key
]
488 r zadd zsetinf1
+inf key
489 r zadd zsetinf2
-inf key
490 r
$cmd zsetinf3
2 zsetinf1 zsetinf2
491 assert_equal
0 [r zscore zsetinf3 key
]
493 r zadd zsetinf1
-inf key
494 r zadd zsetinf2
-inf key
495 r
$cmd zsetinf3
2 zsetinf1 zsetinf2
496 assert_equal
-inf [r zscore zsetinf3 key
]
499 test
"$cmd with NaN weights $encoding" {
500 r del zsetinf1 zsetinf2
502 r zadd zsetinf1
1.0 key
503 r zadd zsetinf2
1.0 key
504 assert_error
"*weight*not*float*" {
505 r
$cmd zsetinf3
2 zsetinf1 zsetinf2 weights nan nan
514 test
{ZINTERSTORE regression with two sets
, intset
+hashtable
} {
518 r zinterstore set3
2 set1 set2
521 test
{ZUNIONSTORE regression
, should not create NaN in scores
} {
523 r zunionstore out
1 z weights
0
524 r zrange out
0 -1 withscores
527 test
{ZINTERSTORE
#516 regression, mixed sets and ziplist zsets} {
528 r sadd one
100 101 102 103
529 r sadd two
100 200 201 202
530 r zadd three
1 500 1 501 1 502 1 503 1 100
531 r zinterstore to_here
3 one two three WEIGHTS
0 0 1
532 r zrange to_here
0 -1
535 proc stressers
{encoding} {
536 if {$encoding == "ziplist"} {
537 # Little extra to allow proper fuzzing in the sorting stresser
538 r config
set zset-max-ziplist-entries
256
539 r config
set zset-max-ziplist-value
64
541 } elseif
{$encoding == "skiplist"} {
542 r config
set zset-max-ziplist-entries
0
543 r config
set zset-max-ziplist-value
0
544 if {$::accurate} {set elements
1000} else {set elements
100}
546 puts "Unknown sorted set encoding"
550 test
"ZSCORE - $encoding" {
553 for {set i
0} {$i < $elements} {incr i
} {
554 set score
[expr rand
()]
556 r zadd zscoretest
$score $i
559 assert_encoding
$encoding zscoretest
560 for {set i
0} {$i < $elements} {incr i
} {
561 assert_equal
[lindex $aux $i] [r zscore zscoretest
$i]
565 test
"ZSCORE after a DEBUG RELOAD - $encoding" {
568 for {set i
0} {$i < $elements} {incr i
} {
569 set score
[expr rand
()]
571 r zadd zscoretest
$score $i
575 assert_encoding
$encoding zscoretest
576 for {set i
0} {$i < $elements} {incr i
} {
577 assert_equal
[lindex $aux $i] [r zscore zscoretest
$i]
581 test
"ZSET sorting stresser - $encoding" {
583 for {set test
0} {$test < 2} {incr test
} {
584 unset -nocomplain auxarray
585 array set auxarray
{}
588 for {set i
0} {$i < $elements} {incr i
} {
590 set score
[expr rand
()]
592 set score
[expr int
(rand
()*10)]
594 set auxarray
($i) $score
595 r zadd myzset
$score $i
597 if {[expr rand
()] < .2} {
598 set j
[expr int
(rand
()*1000)]
600 set score
[expr rand
()]
602 set score
[expr int
(rand
()*10)]
604 set auxarray
($j) $score
605 r zadd myzset
$score $j
608 foreach {item score
} [array get auxarray
] {
609 lappend auxlist
[list $score $item]
611 set sorted
[lsort -command zlistAlikeSort
$auxlist]
614 lappend auxlist
[lindex $x 1]
617 assert_encoding
$encoding myzset
618 set fromredis
[r zrange myzset
0 -1]
620 for {set i
0} {$i < [llength $fromredis]} {incr i
} {
621 if {[lindex $fromredis $i] != [lindex $auxlist $i]} {
626 assert_equal
0 $delta
629 test
"ZRANGEBYSCORE fuzzy test, 100 ranges in $elements element sorted set - $encoding" {
632 for {set i
0} {$i < $elements} {incr i
} {
633 r zadd zset
[expr rand
()] $i
636 assert_encoding
$encoding zset
637 for {set i
0} {$i < 100} {incr i
} {
638 set min
[expr rand
()]
639 set max
[expr rand
()]
645 set low
[r zrangebyscore zset
-inf $min]
646 set ok
[r zrangebyscore zset
$min $max]
647 set high
[r zrangebyscore zset
$max +inf
]
648 set lowx
[r zrangebyscore zset
-inf ($min]
649 set okx
[r zrangebyscore zset
($min ($max]
650 set highx
[r zrangebyscore zset
($max +inf
]
652 if {[r zcount zset
-inf $min] != [llength $low]} {
653 append err
"Error, len does not match zcount\n"
655 if {[r zcount zset
$min $max] != [llength $ok]} {
656 append err
"Error, len does not match zcount\n"
658 if {[r zcount zset
$max +inf
] != [llength $high]} {
659 append err
"Error, len does not match zcount\n"
661 if {[r zcount zset
-inf ($min] != [llength $lowx]} {
662 append err
"Error, len does not match zcount\n"
664 if {[r zcount zset
($min ($max] != [llength $okx]} {
665 append err
"Error, len does not match zcount\n"
667 if {[r zcount zset
($max +inf
] != [llength $highx]} {
668 append err
"Error, len does not match zcount\n"
672 set score
[r zscore zset
$x]
674 append err
"Error, score for $x is $score > $min\n"
678 set score
[r zscore zset
$x]
679 if {$score >= $min} {
680 append err
"Error, score for $x is $score >= $min\n"
684 set score
[r zscore zset
$x]
685 if {$score < $min ||
$score > $max} {
686 append err
"Error, score for $x is $score outside $min-$max range\n"
690 set score
[r zscore zset
$x]
691 if {$score <= $min ||
$score >= $max} {
692 append err
"Error, score for $x is $score outside $min-$max open range\n"
696 set score
[r zscore zset
$x]
698 append err
"Error, score for $x is $score < $max\n"
702 set score
[r zscore zset
$x]
703 if {$score <= $max} {
704 append err
"Error, score for $x is $score <= $max\n"
711 test
"ZSETs skiplist implementation backlink consistency test - $encoding" {
713 for {set j
0} {$j < $elements} {incr j
} {
714 r zadd myzset
[expr rand
()] "Element-$j"
715 r zrem myzset
"Element-[expr int(rand()*$elements)]"
718 assert_encoding
$encoding myzset
719 set l1
[r zrange myzset
0 -1]
720 set l2
[r zrevrange myzset
0 -1]
721 for {set j
0} {$j < [llength $l1]} {incr j
} {
722 if {[lindex $l1 $j] ne
[lindex $l2 end-
$j]} {
729 test
"ZSETs ZRANK augmented skip list stress testing - $encoding" {
732 for {set k
0} {$k < 2000} {incr k
} {
733 set i
[expr {$k % $elements}]
734 if {[expr rand
()] < .2} {
737 set score
[expr rand
()]
738 r zadd myzset
$score $i
739 assert_encoding
$encoding myzset
742 set card
[r zcard myzset
]
744 set index
[randomInt
$card]
745 set ele
[lindex [r zrange myzset
$index $index] 0]
746 set rank
[r zrank myzset
$ele]
747 if {$rank != $index} {
748 set err
"$ele RANK is wrong! ($rank != $index)"