1 start_server 
{tags 
{"sort"}} { 
   2     test 
{SORT ALPHA against integer encoded strings
} { 
  13         test 
{Create a random 
list and a random 
set} { 
  16             for {set i 
0} {$i < 10000} {incr i
} { 
  18                     # Make sure all the weights are different because 
  19                     # Redis does not use a stable sort but Tcl does. 
  21                         set rint 
[expr int
(rand
()*1000000)] 
  23                         set rint 
[expr rand
()] 
  25                     if {![info exists seenrand
($rint)]} break 
  31                 r hset wobj_
$i weight 
$rint 
  32                 lappend tosort 
[list $i $rint] 
  34             set sorted 
[lsort -index 1 -real $tosort] 
  35             for {set i 
0} {$i < 10000} {incr i
} { 
  36                 lappend res 
[lindex $sorted $i 0] 
  41         test 
{SORT with BY against the newly created 
list} { 
  42             r sort tosort 
{BY weight_
*} 
  45         test 
{SORT with BY 
(hash field
) against the newly created 
list} { 
  46             r sort tosort 
{BY wobj_
*->weight
} 
  49         test 
{SORT with GET 
(key
+hash
) with sanity check of each element 
(list)} { 
  51             set l1 
[r sort tosort GET 
# GET weight_*] 
  52             set l2 
[r sort tosort GET 
# GET wobj_*->weight] 
  53             foreach {id1 w1
} $l1 {id2 w2
} $l2 { 
  54                 set realweight 
[r get weight_
$id1] 
  56                     set err 
"ID mismatch $id1 != $id2" 
  59                 if {$realweight != $w1 || 
$realweight != $w2} { 
  60                     set err 
"Weights mismatch! w1: $w1 w2: $w2 real: $realweight" 
  67         test 
{SORT with BY
, but against the newly created 
set} { 
  68             r sort tosort-set 
{BY weight_
*} 
  71         test 
{SORT with BY 
(hash field
), but against the newly created 
set} { 
  72             r sort tosort-set 
{BY wobj_
*->weight
} 
  75         test 
{SORT with BY and STORE against the newly created 
list} { 
  76             r sort tosort 
{BY weight_
*} store sort-res
 
  77             r 
lrange sort-res 
0 -1 
  80         test 
{SORT with BY 
(hash field
) and STORE against the newly created 
list} { 
  81             r sort tosort 
{BY wobj_
*->weight
} store sort-res
 
  82             r 
lrange sort-res 
0 -1 
  85         test 
{SORT direct
, numeric
, against the newly created 
list} { 
  87         } [lsort -integer $res] 
  89         test 
{SORT decreasing sort
} { 
  91         } [lsort -decreasing -integer $res] 
  93         test 
{SORT speed
, sorting 
10000 elements 
list using BY
, 100 times
} { 
  94             set start 
[clock clicks 
-milliseconds] 
  95             for {set i 
0} {$i < 100} {incr i
} { 
  96                 set sorted 
[r sort tosort 
{BY weight_
* LIMIT 
0 10}] 
  98             set elapsed 
[expr [clock clicks 
-milliseconds]-$start] 
  99             puts -nonewline "\n  Average time to sort: [expr double($elapsed)/100] milliseconds " 
 104         test 
{SORT speed
, as above but against hash field
} { 
 105             set start 
[clock clicks 
-milliseconds] 
 106             for {set i 
0} {$i < 100} {incr i
} { 
 107                 set sorted 
[r sort tosort 
{BY wobj_
*->weight LIMIT 
0 10}] 
 109             set elapsed 
[expr [clock clicks 
-milliseconds]-$start] 
 110             puts -nonewline "\n  Average time to sort: [expr double($elapsed)/100] milliseconds " 
 115         test 
{SORT speed
, sorting 
10000 elements 
list directly
, 100 times
} { 
 116             set start 
[clock clicks 
-milliseconds] 
 117             for {set i 
0} {$i < 100} {incr i
} { 
 118                 set sorted 
[r sort tosort 
{LIMIT 
0 10}] 
 120             set elapsed 
[expr [clock clicks 
-milliseconds]-$start] 
 121             puts -nonewline "\n  Average time to sort: [expr double($elapsed)/100] milliseconds " 
 126         test 
{SORT speed
, pseudo-sorting 
10000 elements 
list, BY 
<const
>, 100 times
} { 
 127             set start 
[clock clicks 
-milliseconds] 
 128             for {set i 
0} {$i < 100} {incr i
} { 
 129                 set sorted 
[r sort tosort 
{BY nokey LIMIT 
0 10}] 
 131             set elapsed 
[expr [clock clicks 
-milliseconds]-$start] 
 132             puts -nonewline "\n  Average time to sort: [expr double($elapsed)/100] milliseconds " 
 138     test 
{SORT regression 
for issue 
#19, sorting floats} { 
 140         foreach x 
{1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15} { 
 144     } [lsort -real {1.1 5.10 3.10 7.44 2.1 5.75 6.12 0.25 1.15}] 
 146     test 
{SORT with GET 
#} { 
 151         r mset weight_1 
10 weight_2 
5 weight_3 
30 
 152         r sort mylist BY weight_
* GET 
# 
 155     test 
{SORT with constant GET
} { 
 156         r sort mylist GET foo
 
 159     test 
{SORT against sorted sets
} { 
 166         r sort zset alpha desc
 
 169     test 
{Sorted sets 
+inf and 
-inf handling
} { 
 174         r zadd zset 
1000000 d