From: Dobrica Pavlinusic Date: Sat, 21 Mar 2009 21:40:53 +0000 (+0000) Subject: set, get X-Git-Tag: 0.0801~60 X-Git-Url: http://git.rot13.org/?p=perl-Redis.git;a=commitdiff_plain;h=ca631dea191c0a41b34fe620c3297d2c623bc06b set, get git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/Redis@3 447b33ff-793d-4489-8442-9bea7d161be5 --- diff --git a/lib/Redis.pm b/lib/Redis.pm index 4c46a66..3026ee7 100644 --- a/lib/Redis.pm +++ b/lib/Redis.pm @@ -66,7 +66,7 @@ sub quit { =head2 ping - $r->ping || die "no server?"; + $r->ping || die "no server?"; =cut @@ -76,6 +76,36 @@ sub ping { die "ping failed, got ", dump($pong) unless $pong eq "+PONG\r\n"; } +=head1 Commands operating on string values + +=head2 set + + $r->set( foo => 'bar' ); + +=cut + +sub set { + my ( $self, $k, $v ) = @_; + print $sock "SET $k " . length($v) . "\r\n$v\r\n"; + my $ok = <$sock>; + die dump($ok) unless $ok eq "+OK\r\n"; +} + +=head2 get + + my $value = $r->get( 'foo' ); + +=cut + +sub get { + my ( $self, $k ) = @_; + print $sock "GET $k\r\n"; + my $len = <$sock>; + my $v; + read($sock, $v, $len) || die $!; + return $v; +} + =head1 AUTHOR Dobrica Pavlinusic, C<< >> diff --git a/t/01-Redis.t b/t/01-Redis.t index 1235189..b0c52fc 100755 --- a/t/01-Redis.t +++ b/t/01-Redis.t @@ -3,7 +3,7 @@ use warnings; use strict; -use Test::More tests => 4; +use Test::More tests => 6; use lib 'lib'; @@ -15,4 +15,7 @@ ok( my $o = Redis->new(), 'new' ); ok( $o->ping, 'ping' ); +ok( $o->set( foo => 'bar' ), 'set foo' ); +cmp_ok( $o->get( 'foo' ), 'eq', 'bar', 'get foo' ); + ok( $o->quit, 'quit' );