rpush, refactor _sock_send_bulk to expect +OK
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 22 Mar 2009 09:44:30 +0000 (09:44 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 22 Mar 2009 09:44:30 +0000 (09:44 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/Redis@18 447b33ff-793d-4489-8442-9bea7d161be5

lib/Redis.pm
t/01-Redis.t

index a2b8647..484e9b1 100644 (file)
@@ -75,6 +75,13 @@ sub _sock_ok {
        confess dump($ok) unless $ok eq "+OK\r\n";
 }
 
        confess dump($ok) unless $ok eq "+OK\r\n";
 }
 
+sub _sock_send_bulk {
+       my ( $self, $command, $key, $value ) = @_;
+       print $sock "$command $key " . length($value) . "\r\n$value\r\n";
+       _sock_ok();
+}
+
+
 =head1 Connection Handling
 
 =head2 quit
 =head1 Connection Handling
 
 =head2 quit
@@ -110,9 +117,8 @@ sub ping {
 =cut
 
 sub set {
 =cut
 
 sub set {
-       my ( $self, $k, $v, $new ) = @_;
-       print $sock "SET" . ( $new ? 'NX' : '' ) . " $k " . length($v) . "\r\n$v\r\n";
-       _sock_ok();
+       my ( $self, $key, $value, $new ) = @_;
+       $self->_sock_send_bulk( "SET" . ( $new ? 'NX' : '' ), $key, $value );
 }
 
 =head2 get
 }
 
 =head2 get
@@ -249,6 +255,19 @@ sub dbsize {
        _sock_result();
 }
 
        _sock_result();
 }
 
+=head1 Commands operating on lists
+
+=head2 rpush
+
+  $r->rpush( $key, $value );
+
+=cut
+
+sub rpush {
+       my ( $self, $key, $value ) = @_;
+       $self->_sock_send_bulk('RPUSH', $key, $value);
+}
+
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
index 242a863..2c2ecde 100755 (executable)
@@ -3,7 +3,7 @@
 use warnings;
 use strict;
 
 use warnings;
 use strict;
 
-use Test::More tests => 53;
+use Test::More tests => 54;
 
 use lib 'lib';
 
 
 use lib 'lib';
 
@@ -78,4 +78,11 @@ ok( $@, 'rename to existing key' );
 ok( my $nr_keys = $o->dbsize, 'dbsize' );
 diag "dbsize: $nr_keys";
 
 ok( my $nr_keys = $o->dbsize, 'dbsize' );
 diag "dbsize: $nr_keys";
 
+diag "Commands operating on lists";
+
+ok( $o->rpush( 'test-list' => 'foo' ), 'rpush' );
+
+
+
+
 ok( $o->quit, 'quit' );
 ok( $o->quit, 'quit' );