-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!
+
/* 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) {
}
}
}
+
/* 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) {
}
/* 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);
}
}
close $fd
} e]} {
- puts "Can't PING server at $host:$port... $e"
+ puts -nonewline "."
+ } else {
+ puts -nonewline "ok"
}
return $retval
}
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]
}
-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
-start_server {} {
+start_server {tags {"protocol"}} {
test {Handle an empty query well} {
set fd [r channel]
puts -nonewline $fd "\r\n"
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
}
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" {
}
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" {
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" {
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]]
}
}