exists
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 21 Mar 2009 22:54:10 +0000 (22:54 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 21 Mar 2009 22:54:10 +0000 (22:54 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/Redis@9 447b33ff-793d-4489-8442-9bea7d161be5

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

index d25a225..98235f4 100644 (file)
@@ -150,6 +150,21 @@ sub decr {
        return $count;
 }
 
+=head2 exists
+
+  $r->exists( 'key' ) && print "got key!";
+
+=cut
+
+sub exists {
+       my ( $self, $key ) = @_;
+       print $sock "EXISTS $key\r\n";
+       my $found = <$sock>;
+       $found =~ s{\r\n$}{};
+       warn "# exists $key = $found";
+       return $found;
+}
+
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin at rot13.org> >>
index 1e6092c..06895a7 100755 (executable)
@@ -3,7 +3,7 @@
 use warnings;
 use strict;
 
-use Test::More tests => 37;
+use Test::More tests => 42;
 
 use lib 'lib';
 
@@ -26,6 +26,7 @@ ok( $o->set( foo => 'baz' ), 'set foo => baz' );
 
 cmp_ok( $o->get( 'foo' ), 'eq', 'baz', 'get foo = baz' );
 
+ok( ! $o->exists( 'non-existant' ), 'exists non-existant' );
 ok( ! $o->get( 'non-existant' ), 'get non-existant' );
 
 ok( $o->set('key-next' => 0), 'key-next = 0' );
@@ -36,6 +37,7 @@ ok( $o->set('key-left' => $key_next), 'key-left' );
 
 foreach ( 0 .. $key_next ) {
        ok(     $o->set( "key-$_" => $_ ),           "set key-$_" );
+       ok(  $o->exists( "key-$_"       ),           "exists key-$_" );
        cmp_ok( $o->get( "key-$_"       ), 'eq', $_, "get key-$_" );
        cmp_ok( $o->incr( 'key-next' ), '==', $_ + 1, 'incr' );
        cmp_ok( $o->decr( 'key-left' ), '==', $key_next - $_ - 1, 'decr' );