test non-existing key and strip cr/lf after get value
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 21 Mar 2009 21:53:15 +0000 (21:53 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 21 Mar 2009 21:53:15 +0000 (21:53 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/Redis@4 447b33ff-793d-4489-8442-9bea7d161be5

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

index 3026ee7..bc65da9 100644 (file)
@@ -101,11 +101,18 @@ sub get {
        my ( $self, $k ) = @_;
        print $sock "GET $k\r\n";
        my $len = <$sock>;
        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 $!;
        my $v;
        read($sock, $v, $len) || die $!;
+#      warn "# v: ",dump($v);
+       my $crlf;
+       read($sock, $crlf, 2); # skip cr/lf
        return $v;
 }
 
        return $v;
 }
 
+
+
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
index b0c52fc..0d50d6d 100755 (executable)
@@ -3,7 +3,7 @@
 use warnings;
 use strict;
 
 use warnings;
 use strict;
 
-use Test::More tests => 6;
+use Test::More tests => 93;
 
 use lib 'lib';
 
 
 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->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' );
 ok( $o->quit, 'quit' );