]> git.saurik.com Git - redis.git/blob - tests/unit/type/list.tcl
62ea159dd4566edcb8fcd6865c77af486d20276e
[redis.git] / tests / unit / type / list.tcl
1 start_server {
2 tags {"list"}
3 overrides {
4 "list-max-ziplist-value" 16
5 "list-max-ziplist-entries" 256
6 }
7 } {
8 # We need a value larger than list-max-ziplist-value to make sure
9 # the list has the right encoding when it is swapped in again.
10 array set largevalue {}
11 set largevalue(ziplist) "hello"
12 set largevalue(linkedlist) [string repeat "hello" 4]
13
14 test {LPUSH, RPUSH, LLENGTH, LINDEX - ziplist} {
15 # first lpush then rpush
16 assert_equal 1 [r lpush myziplist1 a]
17 assert_equal 2 [r rpush myziplist1 b]
18 assert_equal 3 [r rpush myziplist1 c]
19 assert_equal 3 [r llen myziplist1]
20 assert_equal a [r lindex myziplist1 0]
21 assert_equal b [r lindex myziplist1 1]
22 assert_equal c [r lindex myziplist1 2]
23 assert_encoding ziplist myziplist1
24
25 # first rpush then lpush
26 assert_equal 1 [r rpush myziplist2 a]
27 assert_equal 2 [r lpush myziplist2 b]
28 assert_equal 3 [r lpush myziplist2 c]
29 assert_equal 3 [r llen myziplist2]
30 assert_equal c [r lindex myziplist2 0]
31 assert_equal b [r lindex myziplist2 1]
32 assert_equal a [r lindex myziplist2 2]
33 assert_encoding ziplist myziplist2
34 }
35
36 test {LPUSH, RPUSH, LLENGTH, LINDEX - regular list} {
37 # first lpush then rpush
38 assert_equal 1 [r lpush mylist1 $largevalue(linkedlist)]
39 assert_encoding linkedlist mylist1
40 assert_equal 2 [r rpush mylist1 b]
41 assert_equal 3 [r rpush mylist1 c]
42 assert_equal 3 [r llen mylist1]
43 assert_equal $largevalue(linkedlist) [r lindex mylist1 0]
44 assert_equal b [r lindex mylist1 1]
45 assert_equal c [r lindex mylist1 2]
46
47 # first rpush then lpush
48 assert_equal 1 [r rpush mylist2 $largevalue(linkedlist)]
49 assert_encoding linkedlist mylist2
50 assert_equal 2 [r lpush mylist2 b]
51 assert_equal 3 [r lpush mylist2 c]
52 assert_equal 3 [r llen mylist2]
53 assert_equal c [r lindex mylist2 0]
54 assert_equal b [r lindex mylist2 1]
55 assert_equal $largevalue(linkedlist) [r lindex mylist2 2]
56 }
57
58 test {DEL a list - ziplist} {
59 assert_equal 1 [r del myziplist2]
60 assert_equal 0 [r exists myziplist2]
61 assert_equal 0 [r llen myziplist2]
62 }
63
64 test {DEL a list - regular list} {
65 assert_equal 1 [r del mylist2]
66 assert_equal 0 [r exists mylist2]
67 assert_equal 0 [r llen mylist2]
68 }
69
70 proc create_ziplist {key entries} {
71 r del $key
72 foreach entry $entries { r rpush $key $entry }
73 assert_encoding ziplist $key
74 }
75
76 proc create_linkedlist {key entries} {
77 r del $key
78 foreach entry $entries { r rpush $key $entry }
79 assert_encoding linkedlist $key
80 }
81
82 foreach {type large} [array get largevalue] {
83 test "BLPOP, BRPOP: single existing list - $type" {
84 set rd [redis_deferring_client]
85 create_$type blist "a b $large c d"
86
87 $rd blpop blist 1
88 assert_equal {blist a} [$rd read]
89 $rd brpop blist 1
90 assert_equal {blist d} [$rd read]
91
92 $rd blpop blist 1
93 assert_equal {blist b} [$rd read]
94 $rd brpop blist 1
95 assert_equal {blist c} [$rd read]
96 }
97
98 test "BLPOP, BRPOP: multiple existing lists - $type" {
99 set rd [redis_deferring_client]
100 create_$type blist1 "a $large c"
101 create_$type blist2 "d $large f"
102
103 $rd blpop blist1 blist2 1
104 assert_equal {blist1 a} [$rd read]
105 $rd brpop blist1 blist2 1
106 assert_equal {blist1 c} [$rd read]
107 assert_equal 1 [r llen blist1]
108 assert_equal 3 [r llen blist2]
109
110 $rd blpop blist2 blist1 1
111 assert_equal {blist2 d} [$rd read]
112 $rd brpop blist2 blist1 1
113 assert_equal {blist2 f} [$rd read]
114 assert_equal 1 [r llen blist1]
115 assert_equal 1 [r llen blist2]
116 }
117
118 test "BLPOP, BRPOP: second list has an entry - $type" {
119 set rd [redis_deferring_client]
120 r del blist1
121 create_$type blist2 "d $large f"
122
123 $rd blpop blist1 blist2 1
124 assert_equal {blist2 d} [$rd read]
125 $rd brpop blist1 blist2 1
126 assert_equal {blist2 f} [$rd read]
127 assert_equal 0 [r llen blist1]
128 assert_equal 1 [r llen blist2]
129 }
130
131 test "BRPOPLPUSH - $type" {
132 r del target
133
134 set rd [redis_deferring_client]
135 create_$type blist "a b $large c d"
136
137 $rd brpoplpush blist target 1
138 assert_equal d [$rd read]
139
140 assert_equal d [r rpop target]
141 assert_equal "a b $large c" [r lrange blist 0 -1]
142 }
143 }
144
145 test "BRPOPLPUSH with zero timeout should block indefinitely" {
146 set rd [redis_deferring_client]
147 r del blist target
148 $rd brpoplpush blist target 0
149 after 1000
150 r rpush blist foo
151 assert_equal foo [$rd read]
152 assert_equal {foo} [r lrange target 0 -1]
153 }
154
155 test "BRPOPLPUSH with a client BLPOPing the target list" {
156 set rd [redis_deferring_client]
157 set rd2 [redis_deferring_client]
158 r del blist target
159 $rd2 blpop target 0
160 $rd brpoplpush blist target 0
161 after 1000
162 r rpush blist foo
163 assert_equal foo [$rd read]
164 assert_equal {target foo} [$rd2 read]
165 assert_equal 0 [r exists target]
166 }
167
168 test "BRPOPLPUSH with wrong source type" {
169 set rd [redis_deferring_client]
170 r del blist target
171 r set blist nolist
172 $rd brpoplpush blist target 1
173 assert_error "ERR*wrong kind*" {$rd read}
174 }
175
176 test "BRPOPLPUSH with wrong destination type" {
177 set rd [redis_deferring_client]
178 r del blist target
179 r set target nolist
180 r lpush blist foo
181 $rd brpoplpush blist target 1
182 assert_error "ERR*wrong kind*" {$rd read}
183
184 set rd [redis_deferring_client]
185 r del blist target
186 r set target nolist
187 $rd brpoplpush blist target 0
188 after 1000
189 r rpush blist foo
190 assert_error "ERR*wrong kind*" {$rd read}
191 assert_equal {foo} [r lrange blist 0 -1]
192 }
193
194 test "BRPOPLPUSH inside a transaction" {
195 r del xlist target
196 r lpush xlist foo
197 r lpush xlist bar
198
199 r multi
200 r brpoplpush xlist target 0
201 r brpoplpush xlist target 0
202 r brpoplpush xlist target 0
203 r lrange xlist 0 -1
204 r lrange target 0 -1
205 r exec
206 } {foo bar {} {} {bar foo}}
207
208 foreach {pop} {BLPOP BRPOP} {
209 test "$pop: with single empty list argument" {
210 set rd [redis_deferring_client]
211 r del blist1
212 $rd $pop blist1 1
213 r rpush blist1 foo
214 assert_equal {blist1 foo} [$rd read]
215 assert_equal 0 [r exists blist1]
216 }
217
218 test "$pop: with negative timeout" {
219 set rd [redis_deferring_client]
220 $rd $pop blist1 -1
221 assert_error "ERR*is negative*" {$rd read}
222 }
223
224 test "$pop: with non-integer timeout" {
225 set rd [redis_deferring_client]
226 $rd $pop blist1 1.1
227 assert_error "ERR*not an integer*" {$rd read}
228 }
229
230 test "$pop: with zero timeout should block indefinitely" {
231 # To test this, use a timeout of 0 and wait a second.
232 # The blocking pop should still be waiting for a push.
233 set rd [redis_deferring_client]
234 $rd $pop blist1 0
235 after 1000
236 r rpush blist1 foo
237 assert_equal {blist1 foo} [$rd read]
238 }
239
240 test "$pop: second argument is not a list" {
241 set rd [redis_deferring_client]
242 r del blist1 blist2
243 r set blist2 nolist
244 $rd $pop blist1 blist2 1
245 assert_error "ERR*wrong kind*" {$rd read}
246 }
247
248 test "$pop: timeout" {
249 set rd [redis_deferring_client]
250 r del blist1 blist2
251 $rd $pop blist1 blist2 1
252 assert_equal {} [$rd read]
253 }
254
255 test "$pop: arguments are empty" {
256 set rd [redis_deferring_client]
257 r del blist1 blist2
258
259 $rd $pop blist1 blist2 1
260 r rpush blist1 foo
261 assert_equal {blist1 foo} [$rd read]
262 assert_equal 0 [r exists blist1]
263 assert_equal 0 [r exists blist2]
264
265 $rd $pop blist1 blist2 1
266 r rpush blist2 foo
267 assert_equal {blist2 foo} [$rd read]
268 assert_equal 0 [r exists blist1]
269 assert_equal 0 [r exists blist2]
270 }
271 }
272
273 test {BLPOP inside a transaction} {
274 r del xlist
275 r lpush xlist foo
276 r lpush xlist bar
277 r multi
278 r blpop xlist 0
279 r blpop xlist 0
280 r blpop xlist 0
281 r exec
282 } {{xlist bar} {xlist foo} {}}
283
284 test {LPUSHX, RPUSHX - generic} {
285 r del xlist
286 assert_equal 0 [r lpushx xlist a]
287 assert_equal 0 [r llen xlist]
288 assert_equal 0 [r rpushx xlist a]
289 assert_equal 0 [r llen xlist]
290 }
291
292 foreach {type large} [array get largevalue] {
293 test "LPUSHX, RPUSHX - $type" {
294 create_$type xlist "$large c"
295 assert_equal 3 [r rpushx xlist d]
296 assert_equal 4 [r lpushx xlist a]
297 assert_equal "a $large c d" [r lrange xlist 0 -1]
298 }
299
300 test "LINSERT - $type" {
301 create_$type xlist "a $large c d"
302 assert_equal 5 [r linsert xlist before c zz]
303 assert_equal "a $large zz c d" [r lrange xlist 0 10]
304 assert_equal 6 [r linsert xlist after c yy]
305 assert_equal "a $large zz c yy d" [r lrange xlist 0 10]
306 assert_equal 7 [r linsert xlist after d dd]
307 assert_equal -1 [r linsert xlist after bad ddd]
308 assert_equal "a $large zz c yy d dd" [r lrange xlist 0 10]
309 assert_equal 8 [r linsert xlist before a aa]
310 assert_equal -1 [r linsert xlist before bad aaa]
311 assert_equal "aa a $large zz c yy d dd" [r lrange xlist 0 10]
312
313 # check inserting integer encoded value
314 assert_equal 9 [r linsert xlist before aa 42]
315 assert_equal 42 [r lrange xlist 0 0]
316 }
317 }
318
319 test {LPUSHX, RPUSHX convert from ziplist to list} {
320 set large $largevalue(linkedlist)
321
322 # convert when a large value is pushed
323 create_ziplist xlist a
324 assert_equal 2 [r rpushx xlist $large]
325 assert_encoding linkedlist xlist
326 create_ziplist xlist a
327 assert_equal 2 [r lpushx xlist $large]
328 assert_encoding linkedlist xlist
329
330 # convert when the length threshold is exceeded
331 create_ziplist xlist [lrepeat 256 a]
332 assert_equal 257 [r rpushx xlist b]
333 assert_encoding linkedlist xlist
334 create_ziplist xlist [lrepeat 256 a]
335 assert_equal 257 [r lpushx xlist b]
336 assert_encoding linkedlist xlist
337 }
338
339 test {LINSERT convert from ziplist to list} {
340 set large $largevalue(linkedlist)
341
342 # convert when a large value is inserted
343 create_ziplist xlist a
344 assert_equal 2 [r linsert xlist before a $large]
345 assert_encoding linkedlist xlist
346 create_ziplist xlist a
347 assert_equal 2 [r linsert xlist after a $large]
348 assert_encoding linkedlist xlist
349
350 # convert when the length threshold is exceeded
351 create_ziplist xlist [lrepeat 256 a]
352 assert_equal 257 [r linsert xlist before a a]
353 assert_encoding linkedlist xlist
354 create_ziplist xlist [lrepeat 256 a]
355 assert_equal 257 [r linsert xlist after a a]
356 assert_encoding linkedlist xlist
357
358 # don't convert when the value could not be inserted
359 create_ziplist xlist [lrepeat 256 a]
360 assert_equal -1 [r linsert xlist before foo a]
361 assert_encoding ziplist xlist
362 create_ziplist xlist [lrepeat 256 a]
363 assert_equal -1 [r linsert xlist after foo a]
364 assert_encoding ziplist xlist
365 }
366
367 foreach {type num} {ziplist 250 linkedlist 500} {
368 proc check_numbered_list_consistency {key} {
369 set len [r llen $key]
370 for {set i 0} {$i < $len} {incr i} {
371 assert_equal $i [r lindex $key $i]
372 assert_equal [expr $len-1-$i] [r lindex $key [expr (-$i)-1]]
373 }
374 }
375
376 proc check_random_access_consistency {key} {
377 set len [r llen $key]
378 for {set i 0} {$i < $len} {incr i} {
379 set rint [expr int(rand()*$len)]
380 assert_equal $rint [r lindex $key $rint]
381 assert_equal [expr $len-1-$rint] [r lindex $key [expr (-$rint)-1]]
382 }
383 }
384
385 test "LINDEX consistency test - $type" {
386 r del mylist
387 for {set i 0} {$i < $num} {incr i} {
388 r rpush mylist $i
389 }
390 assert_encoding $type mylist
391 check_numbered_list_consistency mylist
392 }
393
394 test "LINDEX random access - $type" {
395 assert_encoding $type mylist
396 check_random_access_consistency mylist
397 }
398
399 test "Check if list is still ok after a DEBUG RELOAD - $type" {
400 r debug reload
401 assert_encoding $type mylist
402 check_numbered_list_consistency mylist
403 check_random_access_consistency mylist
404 }
405 }
406
407 test {LLEN against non-list value error} {
408 r del mylist
409 r set mylist foobar
410 assert_error ERR* {r llen mylist}
411 }
412
413 test {LLEN against non existing key} {
414 assert_equal 0 [r llen not-a-key]
415 }
416
417 test {LINDEX against non-list value error} {
418 assert_error ERR* {r lindex mylist 0}
419 }
420
421 test {LINDEX against non existing key} {
422 assert_equal "" [r lindex not-a-key 10]
423 }
424
425 test {LPUSH against non-list value error} {
426 assert_error ERR* {r lpush mylist 0}
427 }
428
429 test {RPUSH against non-list value error} {
430 assert_error ERR* {r rpush mylist 0}
431 }
432
433 foreach {type large} [array get largevalue] {
434 test "RPOPLPUSH base case - $type" {
435 r del mylist1 mylist2
436 create_$type mylist1 "a $large c d"
437 assert_equal d [r rpoplpush mylist1 mylist2]
438 assert_equal c [r rpoplpush mylist1 mylist2]
439 assert_equal "a $large" [r lrange mylist1 0 -1]
440 assert_equal "c d" [r lrange mylist2 0 -1]
441 assert_encoding ziplist mylist2
442 }
443
444 test "RPOPLPUSH with the same list as src and dst - $type" {
445 create_$type mylist "a $large c"
446 assert_equal "a $large c" [r lrange mylist 0 -1]
447 assert_equal c [r rpoplpush mylist mylist]
448 assert_equal "c a $large" [r lrange mylist 0 -1]
449 }
450
451 foreach {othertype otherlarge} [array get largevalue] {
452 test "RPOPLPUSH with $type source and existing target $othertype" {
453 create_$type srclist "a b c $large"
454 create_$othertype dstlist "$otherlarge"
455 assert_equal $large [r rpoplpush srclist dstlist]
456 assert_equal c [r rpoplpush srclist dstlist]
457 assert_equal "a b" [r lrange srclist 0 -1]
458 assert_equal "c $large $otherlarge" [r lrange dstlist 0 -1]
459
460 # When we rpoplpush'ed a large value, dstlist should be
461 # converted to the same encoding as srclist.
462 if {$type eq "linkedlist"} {
463 assert_encoding linkedlist dstlist
464 }
465 }
466 }
467 }
468
469 test {RPOPLPUSH against non existing key} {
470 r del srclist dstlist
471 assert_equal {} [r rpoplpush srclist dstlist]
472 assert_equal 0 [r exists srclist]
473 assert_equal 0 [r exists dstlist]
474 }
475
476 test {RPOPLPUSH against non list src key} {
477 r del srclist dstlist
478 r set srclist x
479 assert_error ERR* {r rpoplpush srclist dstlist}
480 assert_type string srclist
481 assert_equal 0 [r exists newlist]
482 }
483
484 test {RPOPLPUSH against non list dst key} {
485 create_ziplist srclist {a b c d}
486 r set dstlist x
487 assert_error ERR* {r rpoplpush srclist dstlist}
488 assert_type string dstlist
489 assert_equal {a b c d} [r lrange srclist 0 -1]
490 }
491
492 test {RPOPLPUSH against non existing src key} {
493 r del srclist dstlist
494 assert_equal {} [r rpoplpush srclist dstlist]
495 } {}
496
497 foreach {type large} [array get largevalue] {
498 test "Basic LPOP/RPOP - $type" {
499 create_$type mylist "$large 1 2"
500 assert_equal $large [r lpop mylist]
501 assert_equal 2 [r rpop mylist]
502 assert_equal 1 [r lpop mylist]
503 assert_equal 0 [r llen mylist]
504
505 # pop on empty list
506 assert_equal {} [r lpop mylist]
507 assert_equal {} [r rpop mylist]
508 }
509 }
510
511 test {LPOP/RPOP against non list value} {
512 r set notalist foo
513 assert_error ERR*kind* {r lpop notalist}
514 assert_error ERR*kind* {r rpop notalist}
515 }
516
517 foreach {type num} {ziplist 250 linkedlist 500} {
518 test "Mass RPOP/LPOP - $type" {
519 r del mylist
520 set sum1 0
521 for {set i 0} {$i < $num} {incr i} {
522 r lpush mylist $i
523 incr sum1 $i
524 }
525 assert_encoding $type mylist
526 set sum2 0
527 for {set i 0} {$i < [expr $num/2]} {incr i} {
528 incr sum2 [r lpop mylist]
529 incr sum2 [r rpop mylist]
530 }
531 assert_equal $sum1 $sum2
532 }
533 }
534
535 foreach {type large} [array get largevalue] {
536 test "LRANGE basics - $type" {
537 create_$type mylist "$large 1 2 3 4 5 6 7 8 9"
538 assert_equal {1 2 3 4 5 6 7 8} [r lrange mylist 1 -2]
539 assert_equal {7 8 9} [r lrange mylist -3 -1]
540 assert_equal {4} [r lrange mylist 4 4]
541 }
542
543 test "LRANGE inverted indexes - $type" {
544 create_$type mylist "$large 1 2 3 4 5 6 7 8 9"
545 assert_equal {} [r lrange mylist 6 2]
546 }
547
548 test "LRANGE out of range indexes including the full list - $type" {
549 create_$type mylist "$large 1 2 3"
550 assert_equal "$large 1 2 3" [r lrange mylist -1000 1000]
551 }
552
553 test "LRANGE out of range negative end index - $type" {
554 create_$type mylist "$large 1 2 3"
555 assert_equal $large [r lrange mylist 0 -4]
556 assert_equal {} [r lrange mylist 0 -5]
557 }
558 }
559
560 test {LRANGE against non existing key} {
561 assert_equal {} [r lrange nosuchkey 0 1]
562 }
563
564 foreach {type large} [array get largevalue] {
565 proc trim_list {type min max} {
566 upvar 1 large large
567 r del mylist
568 create_$type mylist "1 2 3 4 $large"
569 r ltrim mylist $min $max
570 r lrange mylist 0 -1
571 }
572
573 test "LTRIM basics - $type" {
574 assert_equal "1" [trim_list $type 0 0]
575 assert_equal "1 2" [trim_list $type 0 1]
576 assert_equal "1 2 3" [trim_list $type 0 2]
577 assert_equal "2 3" [trim_list $type 1 2]
578 assert_equal "2 3 4 $large" [trim_list $type 1 -1]
579 assert_equal "2 3 4" [trim_list $type 1 -2]
580 assert_equal "4 $large" [trim_list $type -2 -1]
581 assert_equal "$large" [trim_list $type -1 -1]
582 assert_equal "1 2 3 4 $large" [trim_list $type -5 -1]
583 assert_equal "1 2 3 4 $large" [trim_list $type -10 10]
584 assert_equal "1 2 3 4 $large" [trim_list $type 0 5]
585 assert_equal "1 2 3 4 $large" [trim_list $type 0 10]
586 }
587
588 test "LTRIM out of range negative end index - $type" {
589 assert_equal {1} [trim_list $type 0 -5]
590 assert_equal {} [trim_list $type 0 -6]
591 }
592
593 tags {"slow"} {
594 test "LTRIM stress testing - $type" {
595 set mylist {}
596 set startlen 32
597 r del mylist
598
599 # Start with the large value to ensure the
600 # right encoding is used.
601 r rpush mylist $large
602 lappend mylist $large
603
604 for {set i 0} {$i < $startlen} {incr i} {
605 set str [randomInt 9223372036854775807]
606 r rpush mylist $str
607 lappend mylist $str
608 }
609
610 for {set i 0} {$i < 1000} {incr i} {
611 set min [expr {int(rand()*$startlen)}]
612 set max [expr {$min+int(rand()*$startlen)}]
613 set mylist [lrange $mylist $min $max]
614 r ltrim mylist $min $max
615 assert_equal $mylist [r lrange mylist 0 -1]
616
617 for {set j [r llen mylist]} {$j < $startlen} {incr j} {
618 set str [randomInt 9223372036854775807]
619 r rpush mylist $str
620 lappend mylist $str
621 }
622 }
623 }
624 }
625 }
626
627 foreach {type large} [array get largevalue] {
628 test "LSET - $type" {
629 create_$type mylist "99 98 $large 96 95"
630 r lset mylist 1 foo
631 r lset mylist -1 bar
632 assert_equal "99 foo $large 96 bar" [r lrange mylist 0 -1]
633 }
634
635 test "LSET out of range index - $type" {
636 assert_error ERR*range* {r lset mylist 10 foo}
637 }
638 }
639
640 test {LSET against non existing key} {
641 assert_error ERR*key* {r lset nosuchkey 10 foo}
642 }
643
644 test {LSET against non list value} {
645 r set nolist foobar
646 assert_error ERR*value* {r lset nolist 0 foo}
647 }
648
649 foreach {type e} [array get largevalue] {
650 test "LREM remove all the occurrences - $type" {
651 create_$type mylist "$e foo bar foobar foobared zap bar test foo"
652 assert_equal 2 [r lrem mylist 0 bar]
653 assert_equal "$e foo foobar foobared zap test foo" [r lrange mylist 0 -1]
654 }
655
656 test "LREM remove the first occurrence - $type" {
657 assert_equal 1 [r lrem mylist 1 foo]
658 assert_equal "$e foobar foobared zap test foo" [r lrange mylist 0 -1]
659 }
660
661 test "LREM remove non existing element - $type" {
662 assert_equal 0 [r lrem mylist 1 nosuchelement]
663 assert_equal "$e foobar foobared zap test foo" [r lrange mylist 0 -1]
664 }
665
666 test "LREM starting from tail with negative count - $type" {
667 create_$type mylist "$e foo bar foobar foobared zap bar test foo foo"
668 assert_equal 1 [r lrem mylist -1 bar]
669 assert_equal "$e foo bar foobar foobared zap test foo foo" [r lrange mylist 0 -1]
670 }
671
672 test "LREM starting from tail with negative count (2) - $type" {
673 assert_equal 2 [r lrem mylist -2 foo]
674 assert_equal "$e foo bar foobar foobared zap test" [r lrange mylist 0 -1]
675 }
676
677 test "LREM deleting objects that may be int encoded - $type" {
678 create_$type myotherlist "$e 1 2 3"
679 assert_equal 1 [r lrem myotherlist 1 2]
680 assert_equal 3 [r llen myotherlist]
681 }
682
683 }
684 }
685
686 start_server {
687 tags {list ziplist}
688 overrides {
689 "list-max-ziplist-value" 200000
690 "list-max-ziplist-entries" 256
691 }
692 } {
693 test {Explicit regression for a list bug} {
694 set mylist {49376042582 {BkG2o\pIC]4YYJa9cJ4GWZalG[4tin;1D2whSkCOW`mX;SFXGyS8sedcff3fQI^tgPCC@^Nu1J6o]meM@Lko]t_jRyo<xSJ1oObDYd`ppZuW6P@fS278YaOx=s6lvdFlMbP0[SbkI^Kr\HBXtuFaA^mDx:yzS4a[skiiPWhT<nNfAf=aQVfclcuwDrfe;iVuKdNvB9kbfq>tK?tH[\EvWqS]b`o2OCtjg:?nUTwdjpcUm]y:pg5q24q7LlCOwQE^}}
695 r del l
696 r rpush l [lindex $mylist 0]
697 r rpush l [lindex $mylist 1]
698 assert_equal [r lindex l 0] [lindex $mylist 0]
699 assert_equal [r lindex l 1] [lindex $mylist 1]
700 }
701
702 tags {slow} {
703 test {ziplist implementation: value encoding and backlink} {
704 for {set j 0} {$j < 100} {incr j} {
705 r del l
706 set l {}
707 for {set i 0} {$i < 200} {incr i} {
708 randpath {
709 set data [string repeat x [randomInt 100000]]
710 } {
711 set data [randomInt 65536]
712 } {
713 set data [randomInt 4294967296]
714 } {
715 set data [randomInt 18446744073709551616]
716 }
717 lappend l $data
718 r rpush l $data
719 }
720 assert_equal [llength $l] [r llen l]
721 # Traverse backward
722 for {set i 199} {$i >= 0} {incr i -1} {
723 if {[lindex $l $i] ne [r lindex l $i]} {
724 assert_equal [lindex $l $i] [r lindex l $i]
725 }
726 }
727 }
728 }
729
730 test {ziplist implementation: encoding stress testing} {
731 for {set j 0} {$j < 200} {incr j} {
732 r del l
733 set l {}
734 set len [randomInt 400]
735 for {set i 0} {$i < $len} {incr i} {
736 set rv [randomValue]
737 randpath {
738 lappend l $rv
739 r rpush l $rv
740 } {
741 set l [concat [list $rv] $l]
742 r lpush l $rv
743 }
744 }
745 assert_equal [llength $l] [r llen l]
746 for {set i 0} {$i < 200} {incr i} {
747 if {[lindex $l $i] ne [r lindex l $i]} {
748 assert_equal [lindex $l $i] [r lindex l $i]
749 }
750 }
751 }
752 }
753 }
754 }