]> git.saurik.com Git - redis.git/commitdiff
Merge remote branch 'pietern/issue-300'
authorantirez <antirez@gmail.com>
Tue, 31 Aug 2010 15:39:06 +0000 (17:39 +0200)
committerantirez <antirez@gmail.com>
Tue, 31 Aug 2010 15:39:06 +0000 (17:39 +0200)
README
src/t_list.c
tests/support/server.tcl
tests/unit/other.tcl
tests/unit/protocol.tcl
tests/unit/type/list.tcl
tests/unit/type/set.tcl

diff --git a/README b/README
index a810a7c08abf38d81e02837ad68df5a7a71be135..5eeabf7471294c6f7dfa82cc0f766583b9c0e241 100644 (file)
--- a/README
+++ b/README
@@ -1 +1,68 @@
-Check the 'doc' directory. doc/README.html is a good starting point :)
+Where to find complete Redis documentation?
+-------------------------------------------
+
+This README is just a fast "quick start" document. You can find more detailed
+documentation here:
+
+1) http://code.google.com/p/redis
+2) Check the 'doc' directory. doc/README.html is a good starting point :)
+
+Building Redis
+--------------
+
+It is as simple as:
+
+    % make
+
+Redis is just a single binary, but if you want to install it you can use
+the "make install" target that will copy the binary in /usr/local/bin
+for default.
+
+You can run a 32 bit Redis binary using:
+
+    % make 32bit
+
+After you build Redis is a good idea to test it, using:
+
+    % make test
+
+Running Redis
+-------------
+
+To run Redis with the default configuration just type:
+
+    % cd src
+    % ./redis-server
+    
+If you want to provide your redis.conf, you have to run it using an additional
+parameter (the path of the configuration file):
+
+    % cd src
+    % ./redis-server /path/to/redis.conf
+
+Playing with Redis
+------------------
+
+You can use redis-cli to play with Redis. Start a redis-server instance,
+then in another terminal try the following:
+
+    % cd src
+    % ./redis-cli
+    redis> ping
+    PONG
+    redis> set foo bar
+    OK
+    redis> get foo
+    "bar"
+    redis> incr mycounter
+    (integer) 1
+    redis> incr mycounter
+    (integer) 2
+    redis> 
+
+You can find the list of all the available commands here:
+
+    http://code.google.com/p/redis/wiki/CommandReference
+
+Enjoy!
+
index 6b4a611e47e257ad4a8b09f90610f96533a995a8..add1bee167691b1fcc382c1292c728832f6c65bd 100644 (file)
@@ -782,9 +782,20 @@ int handleClientsWaitingListPush(redisClient *c, robj *key, robj *ele) {
 /* Blocking RPOP/LPOP */
 void blockingPopGenericCommand(redisClient *c, int where) {
     robj *o;
+    long long lltimeout;
     time_t timeout;
     int j;
 
+    /* Make sure timeout is an integer value */
+    if (getLongLongFromObjectOrReply(c,c->argv[c->argc-1],&lltimeout,
+            "timeout is not an integer") != REDIS_OK) return;
+
+    /* Make sure the timeout is not negative */
+    if (lltimeout < 0) {
+        addReplySds(c,sdsnew("-ERR timeout is negative\r\n"));
+        return;
+    }
+
     for (j = 1; j < c->argc-1; j++) {
         o = lookupKeyWrite(c->db,c->argv[j]);
         if (o != NULL) {
@@ -823,6 +834,7 @@ void blockingPopGenericCommand(redisClient *c, int where) {
             }
         }
     }
+
     /* If we are inside a MULTI/EXEC and the list is empty the only thing
      * we can do is treating it as a timeout (even with timeout 0). */
     if (c->flags & REDIS_MULTI) {
@@ -831,7 +843,7 @@ void blockingPopGenericCommand(redisClient *c, int where) {
     }
 
     /* If the list is empty or the key does not exists we must block */
-    timeout = strtol(c->argv[c->argc-1]->ptr,NULL,10);
+    timeout = lltimeout;
     if (timeout > 0) timeout += time(NULL);
     blockForKeys(c,c->argv+1,c->argc-2,timeout);
 }
index 24fef4677175cd4202836e48dfdb9a615a8bfacc..e5ca6c6cd69ffb664990c314bbcde90211c0d794 100644 (file)
@@ -83,7 +83,9 @@ proc ping_server {host port} {
         }
         close $fd
     } e]} {
-        puts "Can't PING server at $host:$port... $e"
+        puts -nonewline "."
+    } else {
+        puts -nonewline "ok"
     }
     return $retval
 }
@@ -170,14 +172,33 @@ proc start_server {options {code undefined}} {
 
     if {$::valgrind} {
         exec valgrind src/redis-server $config_file > $stdout 2> $stderr &
-        after 2000
     } else {
         exec src/redis-server $config_file > $stdout 2> $stderr &
-        after 500
     }
     
     # check that the server actually started
-    if {$code ne "undefined" && ![ping_server $::host $::port]} {
+    # ugly but tries to be as fast as possible...
+    set retrynum 20
+    set serverisup 0
+
+    puts -nonewline "=== ($tags) Starting server ${::host}:${::port} "
+    after 10
+    if {$code ne "undefined"} {
+        while {[incr retrynum -1]} {
+            catch {
+                if {[ping_server $::host $::port]} {
+                    set serverisup 1
+                }
+            }
+            if {$serverisup} break
+            after 50
+        }
+    } else {
+        set serverisup 1
+    }
+    puts {}
+
+    if {!$serverisup} {
         error_and_quit $config_file [exec cat $stderr]
     }
     
index f0497b62c6596d870df81c43ae410ad0d2ff53d3..5967c722dd5fc5563d1642c14daa9e3ca5d07d79 100644 (file)
@@ -1,4 +1,4 @@
-start_server {} {
+start_server {tags {"other"}} {
     test {SAVE - make sure there are all the types as values} {
         # Wait for a background saving in progress to terminate
         waitForBgsave r
index 9eebf77fdf5d96e3e87cb169ce991c4ec243da96..5bf42d7feeed375b33d27efd81dbf5eef2d4d38d 100644 (file)
@@ -1,4 +1,4 @@
-start_server {} {
+start_server {tags {"protocol"}} {
     test {Handle an empty query well} {
         set fd [r channel]
         puts -nonewline $fd "\r\n"
index ca0da764470f73957a2202f04bdfb0853497dc0b..bf188fd709534d366df7d5c79949247a512aca14 100644 (file)
@@ -139,6 +139,28 @@ start_server {
             assert_equal 0 [r exists blist1]
         }
 
+        test "$pop: with negative timeout" {
+            set rd [redis_deferring_client]
+            $rd $pop blist1 -1
+            assert_error "ERR*is negative*" {$rd read}
+        }
+
+        test "$pop: with non-integer timeout" {
+            set rd [redis_deferring_client]
+            $rd $pop blist1 1.1
+            assert_error "ERR*not an integer*" {$rd read}
+        }
+
+        test "$pop: with zero timeout should block indefinitely" {
+            # To test this, use a timeout of 0 and wait a second.
+            # The blocking pop should still be waiting for a push.
+            set rd [redis_deferring_client]
+            $rd $pop blist1 0
+            after 1000
+            r rpush blist1 foo
+            assert_equal {blist1 foo} [$rd read]
+        }
+
         test "$pop: second argument is not a list" {
             set rd [redis_deferring_client]
             r del blist1 blist2
index 056ed27c824ce888cec0952693e2ed0f0384707b..0f9f6abebba0bce9a9f149fdf880ac151bb8a9c5 100644 (file)
@@ -106,14 +106,17 @@ start_server {
         }
         r sadd set5 0
 
-        # it is possible that a hashtable encoded only contains integers,
-        # because it is converted from an intset to a hashtable when a
-        # non-integer element is added and then removed.
+        # To make sure the sets are encoded as the type we are testing -- also
+        # when the VM is enabled and the values may be swapped in and out
+        # while the tests are running -- an extra element is added to every
+        # set that determines its encoding.
+        set large 200
         if {$type eq "hashtable"} {
-            for {set i 1} {$i <= 5} {incr i} {
-                r sadd [format "set%d" $i] foo
-                r srem [format "set%d" $i] foo
-            }
+            set large foo
+        }
+
+        for {set i 1} {$i <= 5} {incr i} {
+            r sadd [format "set%d" $i] $large
         }
 
         test "Generated sets must be encoded as $type" {
@@ -123,20 +126,20 @@ start_server {
         }
 
         test "SINTER with two sets - $type" {
-            assert_equal {195 196 197 198 199} [lsort [r sinter set1 set2]]
+            assert_equal [list 195 196 197 198 199 $large] [lsort [r sinter set1 set2]]
         }
 
         test "SINTERSTORE with two sets - $type" {
             r sinterstore setres set1 set2
-            assert_encoding intset setres
-            assert_equal {195 196 197 198 199} [lsort [r smembers setres]]
+            assert_encoding $type setres
+            assert_equal [list 195 196 197 198 199 $large] [lsort [r smembers setres]]
         }
 
         test "SINTERSTORE with two sets, after a DEBUG RELOAD - $type" {
             r debug reload
             r sinterstore setres set1 set2
-            assert_encoding intset setres
-            assert_equal {195 196 197 198 199} [lsort [r smembers setres]]
+            assert_encoding $type setres
+            assert_equal [list 195 196 197 198 199 $large] [lsort [r smembers setres]]
         }
 
         test "SUNION with two sets - $type" {
@@ -146,18 +149,18 @@ start_server {
 
         test "SUNIONSTORE with two sets - $type" {
             r sunionstore setres set1 set2
-            assert_encoding intset setres
+            assert_encoding $type setres
             set expected [lsort -uniq "[r smembers set1] [r smembers set2]"]
             assert_equal $expected [lsort [r smembers setres]]
         }
 
         test "SINTER against three sets - $type" {
-            assert_equal {195 199} [lsort [r sinter set1 set2 set3]]
+            assert_equal [list 195 199 $large] [lsort [r sinter set1 set2 set3]]
         }
 
         test "SINTERSTORE with three sets - $type" {
             r sinterstore setres set1 set2 set3
-            assert_equal {195 199} [r smembers setres]
+            assert_equal [list 195 199 $large] [lsort [r smembers setres]]
         }
 
         test "SUNION with non existing keys - $type" {
@@ -175,7 +178,9 @@ start_server {
 
         test "SDIFFSTORE with three sets - $type" {
             r sdiffstore setres set1 set4 set5
-            assert_encoding intset setres
+            # The type is determined by type of the first key to diff against.
+            # See the implementation for more information.
+            assert_encoding $type setres
             assert_equal {1 2 3 4} [lsort [r smembers setres]]
         }
     }