--- lib/Redis.pm 2009/03/21 22:38:56 7 +++ lib/Redis.pm 2009/03/21 23:09:48 11 @@ -51,6 +51,13 @@ $self; } +sub _sock_result { + my $result = <$sock>; + warn "# result: ",dump( $result ); + $result =~ s{\r\n$}{} || warn "can't find cr/lf"; + return $result; +} + =head1 Connection Handling =head2 quit @@ -119,6 +126,8 @@ =cut + + sub incr { my ( $self, $key, $value ) = @_; if ( defined $value ) { @@ -126,9 +135,60 @@ } 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(); +} + +=head2 type + + $r->type( 'key' ); # = string + +=cut + +sub type { + my ( $self, $key ) = @_; + print $sock "type $key\r\n"; + _sock_result(); } =head1 AUTHOR