From 5ecd629987e0a79871fdbad482628d70e33e4495 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 21 Mar 2009 23:05:02 +0000 Subject: [PATCH] del, small refacture into sock_result git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/Redis@10 447b33ff-793d-4489-8442-9bea7d161be5 --- lib/Redis.pm | 33 +++++++++++++++++++++++---------- t/01-Redis.t | 6 +++++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/Redis.pm b/lib/Redis.pm index 98235f4..c5597df 100644 --- a/lib/Redis.pm +++ b/lib/Redis.pm @@ -119,6 +119,14 @@ sub get { =cut +sub sock_result { + my $result = <$sock>; + warn "# result: ",dump( $result ); + $result =~ s{\r\n$}{} || warn "can't find cr/lf"; + return $result; +} + + sub incr { my ( $self, $key, $value ) = @_; if ( defined $value ) { @@ -126,9 +134,7 @@ sub incr { } else { print $sock "INCR $key\r\n"; } - my $count = <$sock>; - warn "# $key = $count"; - return $count; + sock_result(); } =head2 decr @@ -145,9 +151,7 @@ sub decr { } else { print $sock "DECR $key\r\n"; } - my $count = <$sock>; - warn "# $key = $count"; - return $count; + sock_result(); } =head2 exists @@ -159,10 +163,19 @@ sub decr { sub exists { my ( $self, $key ) = @_; print $sock "EXISTS $key\r\n"; - my $found = <$sock>; - $found =~ s{\r\n$}{}; - warn "# exists $key = $found"; - return $found; + sock_result(); +} + +=head2 del + + $r->del( 'key' ) || warn "key doesn't exist"; + +=cut + +sub del { + my ( $self, $key ) = @_; + print $sock "DEL $key\r\n"; + sock_result(); } =head1 AUTHOR diff --git a/t/01-Redis.t b/t/01-Redis.t index 06895a7..3e53cf3 100755 --- a/t/01-Redis.t +++ b/t/01-Redis.t @@ -3,7 +3,7 @@ use warnings; use strict; -use Test::More tests => 42; +use Test::More tests => 43; use lib 'lib'; @@ -26,6 +26,8 @@ ok( $o->set( foo => 'baz' ), 'set foo => baz' ); cmp_ok( $o->get( 'foo' ), 'eq', 'baz', 'get foo = baz' ); +$o->del('non-existant'); + ok( ! $o->exists( 'non-existant' ), 'exists non-existant' ); ok( ! $o->get( 'non-existant' ), 'get non-existant' ); @@ -52,4 +54,6 @@ foreach ( 1 .. 3 ) { cmp_ok( $o->decr('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' ); } +ok( $o->del('key-next' ), 'del' ); + ok( $o->quit, 'quit' ); -- 2.20.1