MGET tests added

This commit is contained in:
antirez 2009-03-22 15:27:09 +01:00
parent e255235c20
commit 5b19bd7238

View File

@ -553,6 +553,23 @@ proc main {server port} {
list [redis_lrange $fd mylist 0 -1] $res list [redis_lrange $fd mylist 0 -1] $res
} {{foo bar foobar foobared zap test} 2} } {{foo bar foobar foobared zap test} 2}
test {MGET} {
redis_flushall $fd
redis_set $fd foo BAR
redis_set $fd bar FOO
redis_mget $fd foo bar
} {BAR FOO}
test {MGET against non existing key} {
redis_mget $fd foo baazz bar
} {BAR {} FOO}
test {MGET against non-string key} {
redis_sadd $fd myset ciao
redis_sadd $fd myset bau
redis_mget $fd foo baazz bar myset
} {BAR {} FOO {}}
# Leave the user with a clean DB before to exit # Leave the user with a clean DB before to exit
test {FLUSHALL} { test {FLUSHALL} {
redis_flushall $fd redis_flushall $fd
@ -589,9 +606,10 @@ proc redis_readnl {fd len} {
return $buf return $buf
} }
proc redis_bulk_read fd { proc redis_bulk_read {fd {multi 0}} {
set count [redis_read_integer $fd] set count [redis_read_integer $fd]
if {$count eq {nil}} return {} if {$count eq {nil}} return {}
if {$multi && $count == -1} return {}
set len [expr {abs($count)}] set len [expr {abs($count)}]
set buf [redis_readnl $fd $len] set buf [redis_readnl $fd $len]
if {$count < 0} {return "***ERROR*** $buf"} if {$count < 0} {return "***ERROR*** $buf"}
@ -608,7 +626,7 @@ proc redis_multi_bulk_read fd {
} }
set l {} set l {}
for {set i 0} {$i < $count} {incr i} { for {set i 0} {$i < $count} {incr i} {
lappend l [redis_bulk_read $fd] lappend l [redis_bulk_read $fd 1]
} }
return $l return $l
} }
@ -710,6 +728,11 @@ proc redis_lrange {fd key first last} {
redis_multi_bulk_read $fd redis_multi_bulk_read $fd
} }
proc redis_mget {fd args} {
redis_writenl $fd "mget [join $args]"
redis_multi_bulk_read $fd
}
proc redis_sort {fd key {params {}}} { proc redis_sort {fd key {params {}}} {
redis_writenl $fd "sort $key $params" redis_writenl $fd "sort $key $params"
redis_multi_bulk_read $fd redis_multi_bulk_read $fd