X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/958694375564578103bb053d3845f3d4a89b8e4e..e197b441a2bc18c5b0c8ba4d2aafd5f79e54c058:/client-libraries/tcl/redis.tcl diff --git a/client-libraries/tcl/redis.tcl b/client-libraries/tcl/redis.tcl index 6cc713d2..86b7eb48 100644 --- a/client-libraries/tcl/redis.tcl +++ b/client-libraries/tcl/redis.tcl @@ -16,14 +16,24 @@ namespace eval redis {} set ::redis::id 0 array set ::redis::fd {} array set ::redis::bulkarg {} +array set ::redis::multibulkarg {} # Flag commands requiring last argument as a bulk write operation foreach redis_bulk_cmd { - set setnx rpush lpush lset lrem sadd srem sismember echo + set setnx rpush lpush lset lrem sadd srem sismember echo getset smove zadd } { set ::redis::bulkarg($redis_bulk_cmd) {} } + +# Flag commands requiring last argument as a bulk write operation +foreach redis_multibulk_cmd { + mset msetnx +} { + set ::redis::multibulkarg($redis_multibulk_cmd) {} +} + unset redis_bulk_cmd +unset redis_multibulk_cmd proc redis {{server 127.0.0.1} {port 6379}} { set fd [socket $server $port] @@ -36,15 +46,25 @@ proc redis {{server 127.0.0.1} {port 6379}} { proc ::redis::__dispatch__ {id method args} { set fd $::redis::fd($id) if {[info command ::redis::__method__$method] eq {}} { - set cmd "$method " if {[info exists ::redis::bulkarg($method)]} { + set cmd "$method " append cmd [join [lrange $args 0 end-1]] append cmd " [string length [lindex $args end]]\r\n" append cmd [lindex $args end] + ::redis::redis_writenl $fd $cmd + } elseif {[info exists ::redis::multibulkarg($method)]} { + set cmd "*[expr {[llength $args]+1}]\r\n" + append cmd "$[string length $method]\r\n$method\r\n" + foreach a $args { + append cmd "$[string length $a]\r\n$a\r\n" + } + ::redis::redis_write $fd $cmd + flush $fd } else { + set cmd "$method " append cmd [join $args] + ::redis::redis_writenl $fd $cmd } - ::redis::redis_writenl $fd $cmd ::redis::redis_read_reply $fd } else { uplevel 1 [list ::redis::__method__$method $id $fd] $args @@ -106,6 +126,6 @@ proc ::redis::redis_read_reply fd { - {return -code error [redis_read_line $fd]} $ {redis_bulk_read $fd} * {redis_multi_bulk_read $fd} - default {return -code error "Bad protocl, $type as reply type byte"} + default {return -code error "Bad protocol, $type as reply type byte"} } }