]> git.saurik.com Git - redis.git/blobdiff - test-redis.tcl
Minimal support for subscribe/psubscribe in redis-cli
[redis.git] / test-redis.tcl
index 8ba1ff85838e9a94805f9790304ea8a45a4f22f6..26b7f12a7e3f29c0e4f4e39c96b426c9857d4ce1 100644 (file)
@@ -935,6 +935,15 @@ proc main {} {
         lsort [array names myset]
     } {a b c}
 
+    test {SORT ALPHA against integer encoded strings} {
+        $r del mylist
+        $r lpush mylist 2
+        $r lpush mylist 1
+        $r lpush mylist 3
+        $r lpush mylist 10
+        $r sort mylist alpha
+    } {1 10 2 3}
+
     test {Create a random list and a random set} {
         set tosort {}
         array set seenrand {}
@@ -953,6 +962,7 @@ proc main {} {
             $r lpush tosort $i
             $r sadd tosort-set $i
             $r set weight_$i $rint
+            $r hset wobj_$i weight $rint
             lappend tosort [list $i $rint]
         }
         set sorted [lsort -index 1 -real $tosort]
@@ -967,15 +977,46 @@ proc main {} {
         $r sort tosort {BY weight_*}
     } $res
 
-    test {the same SORT with BY, but against the newly created set} {
+    test {SORT with BY (hash field) against the newly created list} {
+        $r sort tosort {BY wobj_*->weight}
+    } $res
+
+    test {SORT with GET (key+hash) with sanity check of each element (list)} {
+        set err {}
+        set l1 [$r sort tosort GET # GET weight_*]
+        set l2 [$r sort tosort GET # GET wobj_*->weight]
+        foreach {id1 w1} $l1 {id2 w2} $l2 {
+            set realweight [$r get weight_$id1]
+            if {$id1 != $id2} {
+                set err "ID mismatch $id1 != $id2"
+                break
+            }
+            if {$realweight != $w1 || $realweight != $w2} {
+                set err "Weights mismatch! w1: $w1 w2: $w2 real: $realweight"
+                break
+            }
+        }
+        set _ $err
+    } {}
+
+    test {SORT with BY, but against the newly created set} {
         $r sort tosort-set {BY weight_*}
     } $res
 
+    test {SORT with BY (hash field), but against the newly created set} {
+        $r sort tosort-set {BY wobj_*->weight}
+    } $res
+
     test {SORT with BY and STORE against the newly created list} {
         $r sort tosort {BY weight_*} store sort-res
         $r lrange sort-res 0 -1
     } $res
 
+    test {SORT with BY (hash field) and STORE against the newly created list} {
+        $r sort tosort {BY wobj_*->weight} store sort-res
+        $r lrange sort-res 0 -1
+    } $res
+
     test {SORT direct, numeric, against the newly created list} {
         $r sort tosort
     } [lsort -integer $res]
@@ -995,6 +1036,17 @@ proc main {} {
         format {}
     } {}
 
+    test {SORT speed, as above but against hash field} {
+        set start [clock clicks -milliseconds]
+        for {set i 0} {$i < 100} {incr i} {
+            set sorted [$r sort tosort {BY wobj_*->weight LIMIT 0 10}]
+        }
+        set elapsed [expr [clock clicks -milliseconds]-$start]
+        puts -nonewline "\n  Average time to sort: [expr double($elapsed)/100] milliseconds "
+        flush stdout
+        format {}
+    } {}
+
     test {SORT speed, sorting 10000 elements list directly, 100 times} {
         set start [clock clicks -milliseconds]
         for {set i 0} {$i < 100} {incr i} {
@@ -1652,6 +1704,30 @@ proc main {} {
         set _ $rv
     } {0 newval1 1 0 newval2 1 1 1}
 
+    test {HSETNX target key missing - small hash} {
+        $r hsetnx smallhash __123123123__ foo
+        $r hget smallhash __123123123__
+    } {foo}
+
+    test {HSETNX target key exists - small hash} {
+        $r hsetnx smallhash __123123123__ bar
+        set result [$r hget smallhash __123123123__]
+        $r hdel smallhash __123123123__
+        set _ $result
+    } {foo}
+
+    test {HSETNX target key missing - big hash} {
+        $r hsetnx bighash __123123123__ foo
+        $r hget bighash __123123123__
+    } {foo}
+
+    test {HSETNX target key exists - big hash} {
+        $r hsetnx bighash __123123123__ bar
+        set result [$r hget bighash __123123123__]
+        $r hdel bighash __123123123__
+        set _ $result
+    } {foo}
+
     test {HMSET wrong number of args} {
         catch {$r hmset smallhash key1 val1 key2} err
         format $err
@@ -1865,6 +1941,30 @@ proc main {} {
         $r ttl x
     } {1[345]}
 
+    test {SETEX - Set + Expire combo operation. Check for TTL} {
+        $r setex x 12 test
+        $r ttl x
+    } {1[012]}
+
+    test {SETEX - Check value} {
+        $r get x
+    } {test}
+
+    test {SETEX - Overwrite old key} {
+        $r setex y 1 foo
+        $r get y
+    } {foo}
+
+    test {SETEX - Wait for the key to expire} {
+        after 3000
+        $r get y
+    } {}
+
+    test {SETEX - Wrong time parameter} {
+        catch {$r setex z -10 foo} e
+        set _ $e
+    } {*invalid expire*}
+
     test {ZSETs skiplist implementation backlink consistency test} {
         set diff 0
         set elements 10000