From: Dobrica Pavlinusic Date: Sat, 21 Mar 2009 21:53:15 +0000 (+0000) Subject: test non-existing key and strip cr/lf after get value X-Git-Tag: 0.0801~59 X-Git-Url: http://git.rot13.org/?p=perl-Redis.git;a=commitdiff_plain;h=3e0104f8caed52c0991f2662b80aa8c137df77ad test non-existing key and strip cr/lf after get value git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/Redis@4 447b33ff-793d-4489-8442-9bea7d161be5 --- diff --git a/lib/Redis.pm b/lib/Redis.pm index 3026ee7..bc65da9 100644 --- a/lib/Redis.pm +++ b/lib/Redis.pm @@ -101,11 +101,18 @@ sub get { my ( $self, $k ) = @_; print $sock "GET $k\r\n"; my $len = <$sock>; +# warn "# len: ",dump($len); + return undef if $len eq "nil\r\n"; my $v; read($sock, $v, $len) || die $!; +# warn "# v: ",dump($v); + my $crlf; + read($sock, $crlf, 2); # skip cr/lf return $v; } + + =head1 AUTHOR Dobrica Pavlinusic, C<< >> diff --git a/t/01-Redis.t b/t/01-Redis.t index b0c52fc..0d50d6d 100755 --- a/t/01-Redis.t +++ b/t/01-Redis.t @@ -3,7 +3,7 @@ use warnings; use strict; -use Test::More tests => 6; +use Test::More tests => 93; use lib 'lib'; @@ -18,4 +18,11 @@ ok( $o->ping, 'ping' ); ok( $o->set( foo => 'bar' ), 'set foo' ); cmp_ok( $o->get( 'foo' ), 'eq', 'bar', 'get foo' ); +ok( ! $o->get( 'non-existant' ), 'get non-existant' ); + +foreach ( 0 .. 42 ) { + ok( $o->set( "key-$_" => $_ ), "set key-$_" ); + cmp_ok( $o->get( "key-$_" ), 'eq', $_, "get key-$_" ); +} + ok( $o->quit, 'quit' );