uses only the multi-bulk protocol
authorDirk Vleugels <dvl@2scale.net>
Tue, 23 Mar 2010 17:10:36 +0000 (18:10 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 23 Mar 2010 17:10:36 +0000 (18:10 +0100)
http://groups.google.com/group/redis-db/browse_thread/thread/4b266d0f6f11d9ba/adf47fd931f62787

lib/Redis.pm

index 55fd1a1..75bc088 100644 (file)
@@ -55,22 +55,6 @@ sub new {
        $self;
 }
 
-my $bulk_command = {
-       set => 1,       setnx => 1,
-       rpush => 1,     lpush => 1,
-       lset => 1,      lrem => 1,
-       sadd => 1,      srem => 1,
-       sismember => 1,
-       echo => 1,
-       getset => 1,
-       smove => 1,
-       zadd => 1,
-       zrem => 1,
-       zscore => 1,
-       zincrby => 1,
-       append => 1,
-};
-
 # we don't want DESTROY to fallback into AUTOLOAD
 sub DESTROY {}
 
@@ -87,27 +71,13 @@ sub AUTOLOAD {
 
        warn "## $command ",Dumper(@_) if $self->{debug};
 
-       my $send;
-
-       if ( defined $bulk_command->{$command} ) {
-               my $value = pop;
-               $value = '' if ! defined $value;
-               $send
-                       = uc($command)
-                       . ' '
-                       . join(' ', @_)
-                       . ' ' 
-                       . length( $value )
-                       . "\r\n$value\r\n"
-                       ;
-       } else {
-               $send
-                       = uc($command)
-                       . ' '
-                       . join(' ', @_)
+       unshift @_, uc($command);
+
+       my $send
+                       = "*".(scalar @_)
                        . "\r\n"
+                       . join("", map { "\$". length($_) ."\r\n". $_ ."\r\n" } @_)
                        ;
-       }
 
        warn ">> $send" if $self->{debug};
        print $sock $send;