puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
incr ::failed
}
+ if {$::traceleaks} {
+ if {![string match {*0 leaks*} [exec leaks redis-server]]} {
+ puts "--------- Test $::testnum LEAKED! --------"
+ exit 1
+ }
+ }
}
proc randstring {min max {type binary}} {
return $digest
}
-proc main {server port} {
- set r [redis $server $port]
+proc main {} {
+ set r [redis $::host $::port]
$r select 9
set err ""
set res ""
# The following AUTH test should be enabled only when requirepass
# <PASSWORD> is set in redis.conf and redis-server was started with
- # redis.conf as the first argument.
+ # redis.conf as the first argument.
#test {AUTH with requirepass in redis.conf} {
# $r auth foobared
$r incrby novar 17179869184
} {34359738368}
- test {INCR against key with spaces (no integer encoded)} {
+ test {INCR fails against key with spaces (no integer encoded)} {
$r set novar " 11 "
- $r incr novar
- } {12}
+ catch {$r incr novar} err
+ format $err
+ } {ERR*}
+
+ test {INCR fails against a key holding a list} {
+ $r rpush mylist 1
+ catch {$r incr novar} err
+ $r rpop mylist
+ format $err
+ } {ERR*}
test {DECRBY over 32bit value with over 32bit increment, negative res} {
$r set novar 17179869184
test {SUNION with two sets} {
lsort [$r sunion set1 set2]
} [lsort -uniq "[$r smembers set1] [$r smembers set2]"]
-
+
test {SINTERSTORE with two sets} {
$r sinterstore setres set1 set2
lsort [$r smembers setres]
$r lpush mysavelist world
$r set myemptykey {}
$r set mynormalkey {blablablba}
- $r zadd mytestzset a 10
- $r zadd mytestzset b 20
- $r zadd mytestzset c 30
+ $r zadd mytestzset 10 a
+ $r zadd mytestzset 20 b
+ $r zadd mytestzset 30 c
$r save
} {OK}
}
lsort [array names myset]
} {a b c}
-
+
test {Create a random list and a random set} {
set tosort {}
array set seenrand {}
set _ $err
} {}
+ test {HGET against non existing key} {
+ set rv {}
+ lappend rv [$r hget smallhash __123123123__]
+ lappend rv [$r hget bighash __123123123__]
+ set _ $rv
+ } {{} {}}
+
test {HSET in update and insert mode} {
set rv {}
set k [lindex [array names smallhash *] 0]
set _ $rv
} {0 newval1 1 0 newval2 1 1 1}
- test {HGET against non existing key} {
+ 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
+ } {*wrong number*}
+
+ test {HMSET - small hash} {
+ set args {}
+ foreach {k v} [array get smallhash] {
+ set newval [randstring 0 8 alpha]
+ set smallhash($k) $newval
+ lappend args $k $newval
+ }
+ $r hmset smallhash {*}$args
+ } {OK}
+
+ test {HMSET - big hash} {
+ set args {}
+ foreach {k v} [array get bighash] {
+ set newval [randstring 0 8 alpha]
+ set bighash($k) $newval
+ lappend args $k $newval
+ }
+ $r hmset bighash {*}$args
+ } {OK}
+
+ test {HMGET against non existing key and fields} {
set rv {}
- lappend rv [$r hget smallhash __123123123__]
- lappend rv [$r hget bighash __123123123__]
+ lappend rv [$r hmget doesntexist __123123123__ __456456456__]
+ lappend rv [$r hmget smallhash __123123123__ __456456456__]
+ lappend rv [$r hmget bighash __123123123__ __456456456__]
set _ $rv
- } {{} {}}
+ } {{{} {}} {{} {}} {{} {}}}
+
+ test {HMGET - small hash} {
+ set keys {}
+ set vals {}
+ foreach {k v} [array get smallhash] {
+ lappend keys $k
+ lappend vals $v
+ }
+ set err {}
+ set result [$r hmget smallhash {*}$keys]
+ if {$vals ne $result} {
+ set err "$vals != $result"
+ break
+ }
+ set _ $err
+ } {}
+
+ test {HMGET - big hash} {
+ set keys {}
+ set vals {}
+ foreach {k v} [array get bighash] {
+ lappend keys $k
+ lappend vals $v
+ }
+ set err {}
+ set result [$r hmget bighash {*}$keys]
+ if {$vals ne $result} {
+ set err "$vals != $result"
+ break
+ }
+ set _ $err
+ } {}
test {HKEYS - small hash} {
lsort [$r hkeys smallhash]
} {1 1}
test {PIPELINING stresser (also a regression for the old epoll bug)} {
- set fd2 [socket 127.0.0.1 6379]
+ set fd2 [socket $::host $::port]
fconfigure $fd2 -encoding binary -translation binary
puts -nonewline $fd2 "SELECT 9\r\n"
flush $fd2
}
proc stress {} {
- set r [redis]
+ set r [redis $::host $::port]
$r select 9
$r flushdb
while 1 {
set ::host 127.0.0.1
set ::port 6379
set ::stress 0
+set ::traceleaks 0
set ::flush 0
set ::first 0
set ::last 1000000
} elseif {$opt eq {-p} && !$lastarg} {
set ::port $arg
incr j
- } elseif {$opt eq {-stress}} {
+ } elseif {$opt eq {--stress}} {
set ::stress 1
+ } elseif {$opt eq {--trace-leaks}} {
+ set ::traceleaks 1
} elseif {$opt eq {--flush}} {
set ::flush 1
} elseif {$opt eq {--first} && !$lastarg} {
}
# Before to run the test check if DB 9 and DB 10 are empty
-set r [redis]
+set r [redis $::host $::port]
if {$::flush} {
$r flushall
unset db9size
unset db10size
+puts "Testing Redis, host $::host, port $::port"
if {$::stress} {
stress
} else {
- main $::host $::port
+ main
}