From b8c759eed57f05e57445c661a30cab09a5fb2707 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 22 Mar 2009 09:44:30 +0000 Subject: [PATCH] rpush, refactor _sock_send_bulk to expect +OK git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/Redis@18 447b33ff-793d-4489-8442-9bea7d161be5 --- lib/Redis.pm | 25 ++++++++++++++++++++++--- t/01-Redis.t | 9 ++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/Redis.pm b/lib/Redis.pm index a2b8647..484e9b1 100644 --- a/lib/Redis.pm +++ b/lib/Redis.pm @@ -75,6 +75,13 @@ sub _sock_ok { 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 @@ -110,9 +117,8 @@ sub ping { =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 @@ -249,6 +255,19 @@ sub dbsize { _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<< >> diff --git a/t/01-Redis.t b/t/01-Redis.t index 242a863..2c2ecde 100755 --- a/t/01-Redis.t +++ b/t/01-Redis.t @@ -3,7 +3,7 @@ use warnings; use strict; -use Test::More tests => 53; +use Test::More tests => 54; use lib 'lib'; @@ -78,4 +78,11 @@ ok( $@, 'rename to existing key' ); 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' ); -- 2.20.1