X-Git-Url: http://git.rot13.org/?p=perl-Redis.git;a=blobdiff_plain;f=lib%2FRedis.pm;h=c5597df58503e333250181c7ee968bfdbc72cb9d;hp=952b80bb12f594621174f9296807a6a368eb1205;hb=5ecd629987e0a79871fdbad482628d70e33e4495;hpb=034e1cea13802c977bd220d8e393c4091d3a99bf diff --git a/lib/Redis.pm b/lib/Redis.pm index 952b80b..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,48 @@ sub incr { } else { print $sock "INCR $key\r\n"; } - my $count = <$sock>; - warn "# $key = $count"; - return $count; + sock_result(); +} + +=head2 decr + + $r->decr('counter'); + $r->decr('tripplets', 3); + +=cut + +sub decr { + my ( $self, $key, $value ) = @_; + if ( defined $value ) { + print $sock "DECRBY $key $value\r\n"; + } else { + print $sock "DECR $key\r\n"; + } + sock_result(); +} + +=head2 exists + + $r->exists( 'key' ) && print "got key!"; + +=cut + +sub exists { + my ( $self, $key ) = @_; + print $sock "EXISTS $key\r\n"; + 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