=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 ) {
} else {
print $sock "INCR $key\r\n";
}
- my $count = <$sock>;
- warn "# $key = $count";
- return $count;
+ sock_result();
}
=head2 decr
} else {
print $sock "DECR $key\r\n";
}
- my $count = <$sock>;
- warn "# $key = $count";
- return $count;
+ sock_result();
}
=head2 exists
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
use warnings;
use strict;
-use Test::More tests => 42;
+use Test::More tests => 43;
use lib 'lib';
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' );
cmp_ok( $o->decr('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' );
}
+ok( $o->del('key-next' ), 'del' );
+
ok( $o->quit, 'quit' );