1 start_server
default.conf
{} {
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
165 test
{ZRANGEBYSCORE fuzzy test
, 100 ranges in
1000 elements sorted
set} {
168 for {set i
0} {$i < 1000} {incr i
} {
169 r zadd zset
[expr rand
()] $i
171 for {set i
0} {$i < 100} {incr i
} {
172 set min
[expr rand
()]
173 set max
[expr rand
()]
179 set low
[r zrangebyscore zset
-inf $min]
180 set ok
[r zrangebyscore zset
$min $max]
181 set high
[r zrangebyscore zset
$max +inf
]
182 set lowx
[r zrangebyscore zset
-inf ($min]
183 set okx
[r zrangebyscore zset
($min ($max]
184 set highx
[r zrangebyscore zset
($max +inf
]
186 if {[r zcount zset
-inf $min] != [llength $low]} {
187 append err
"Error, len does not match zcount\n"
189 if {[r zcount zset
$min $max] != [llength $ok]} {
190 append err
"Error, len does not match zcount\n"
192 if {[r zcount zset
$max +inf
] != [llength $high]} {
193 append err
"Error, len does not match zcount\n"
195 if {[r zcount zset
-inf ($min] != [llength $lowx]} {
196 append err
"Error, len does not match zcount\n"
198 if {[r zcount zset
($min ($max] != [llength $okx]} {
199 append err
"Error, len does not match zcount\n"
201 if {[r zcount zset
($max +inf
] != [llength $highx]} {
202 append err
"Error, len does not match zcount\n"
206 set score
[r zscore zset
$x]
208 append err
"Error, score for $x is $score > $min\n"
212 set score
[r zscore zset
$x]
213 if {$score >= $min} {
214 append err
"Error, score for $x is $score >= $min\n"
218 set score
[r zscore zset
$x]
219 if {$score < $min ||
$score > $max} {
220 append err
"Error, score for $x is $score outside $min-$max range\n"
224 set score
[r zscore zset
$x]
225 if {$score <= $min ||
$score >= $max} {
226 append err
"Error, score for $x is $score outside $min-$max open range\n"
230 set score
[r zscore zset
$x]
232 append err
"Error, score for $x is $score < $max\n"
236 set score
[r zscore zset
$x]
237 if {$score <= $max} {
238 append err
"Error, score for $x is $score <= $max\n"
245 test
{ZRANGEBYSCORE with LIMIT
} {
253 [r zrangebyscore zset
0 10 LIMIT
0 2] \
254 [r zrangebyscore zset
0 10 LIMIT
2 3] \
255 [r zrangebyscore zset
0 10 LIMIT
2 10] \
256 [r zrangebyscore zset
0 10 LIMIT
20 10]
257 } {{a b
} {c d e
} {c d e
} {}}
259 test
{ZRANGEBYSCORE with LIMIT and withscores
} {
266 r zrangebyscore zset
20 50 LIMIT
2 3 withscores
269 test
{ZREMRANGEBYSCORE basics
} {
276 list [r zremrangebyscore zset
2 4] [r zrange zset
0 -1]
279 test
{ZREMRANGEBYSCORE from
-inf to
+inf
} {
286 list [r zremrangebyscore zset
-inf +inf
] [r zrange zset
0 -1]
289 test
{ZREMRANGEBYRANK basics
} {
296 list [r zremrangebyrank zset
1 3] [r zrange zset
0 -1]
299 test
{ZUNIONSTORE against non-existing key doesn't
set destination
} {
301 list [r zunionstore dst_key
1 zseta
] [r exists dst_key
]
304 test
{ZUNIONSTORE basics
} {
305 r del zseta zsetb zsetc
312 list [r zunionstore zsetc
2 zseta zsetb
] [r zrange zsetc
0 -1 withscores
]
313 } {4 {a
1 b
3 d
3 c
5}}
315 test
{ZUNIONSTORE with weights
} {
316 list [r zunionstore zsetc
2 zseta zsetb weights
2 3] [r zrange zsetc
0 -1 withscores
]
317 } {4 {a
2 b
7 d
9 c
12}}
319 test
{ZUNIONSTORE with a regular
set and weights
} {
324 list [r zunionstore zsetc
2 seta zsetb weights
2 3] [r zrange zsetc
0 -1 withscores
]
325 } {4 {a
2 b
5 c
8 d
9}}
327 test
{ZUNIONSTORE with AGGREGATE MIN
} {
328 list [r zunionstore zsetc
2 zseta zsetb aggregate min
] [r zrange zsetc
0 -1 withscores
]
329 } {4 {a
1 b
1 c
2 d
3}}
331 test
{ZUNIONSTORE with AGGREGATE MAX
} {
332 list [r zunionstore zsetc
2 zseta zsetb aggregate max
] [r zrange zsetc
0 -1 withscores
]
333 } {4 {a
1 b
2 c
3 d
3}}
335 test
{ZINTERSTORE basics
} {
336 list [r zinterstore zsetc
2 zseta zsetb
] [r zrange zsetc
0 -1 withscores
]
339 test
{ZINTERSTORE with weights
} {
340 list [r zinterstore zsetc
2 zseta zsetb weights
2 3] [r zrange zsetc
0 -1 withscores
]
343 test
{ZINTERSTORE with a regular
set and weights
} {
348 list [r zinterstore zsetc
2 seta zsetb weights
2 3] [r zrange zsetc
0 -1 withscores
]
351 test
{ZINTERSTORE with AGGREGATE MIN
} {
352 list [r zinterstore zsetc
2 zseta zsetb aggregate min
] [r zrange zsetc
0 -1 withscores
]
355 test
{ZINTERSTORE with AGGREGATE MAX
} {
356 list [r zinterstore zsetc
2 zseta zsetb aggregate max
] [r zrange zsetc
0 -1 withscores
]
359 test
{ZSETs skiplist implementation backlink consistency test
} {
362 for {set j
0} {$j < $elements} {incr j
} {
363 r zadd myzset
[expr rand
()] "Element-$j"
364 r zrem myzset
"Element-[expr int(rand()*$elements)]"
366 set l1
[r zrange myzset
0 -1]
367 set l2
[r zrevrange myzset
0 -1]
368 for {set j
0} {$j < [llength $l1]} {incr j
} {
369 if {[lindex $l1 $j] ne
[lindex $l2 end-
$j]} {
376 test
{ZSETs ZRANK augmented skip
list stress testing
} {
379 for {set k
0} {$k < 10000} {incr k
} {
380 set i
[expr {$k%1000}]
381 if {[expr rand
()] < .2} {
384 set score
[expr rand
()]
385 r zadd myzset
$score $i
387 set card
[r zcard myzset
]
389 set index
[randomInt
$card]
390 set ele
[lindex [r zrange myzset
$index $index] 0]
391 set rank
[r zrank myzset
$ele]
392 if {$rank != $index} {
393 set err
"$ele RANK is wrong! ($rank != $index)"
401 test
{ZSET element can't be
set to nan with ZADD
} {
403 catch {r zadd myzset nan abc
} e
407 test
{ZSET element can't be
set to nan with ZINCRBY
} {
409 catch {r zincrby myzset nan abc
} e
413 test
{ZINCRBY calls leading to Nan are refused
} {
415 r zincrby myzset
+inf abc
416 catch {r zincrby myzset
-inf abc
} e