From 220f99f0edbe8fb1b5e6a4b9cfbf13d6b85623fb Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 21 Mar 2009 22:54:10 +0000 Subject: [PATCH] exists git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/Redis@9 447b33ff-793d-4489-8442-9bea7d161be5 --- lib/Redis.pm | 15 +++++++++++++++ t/01-Redis.t | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Redis.pm b/lib/Redis.pm index d25a225..98235f4 100644 --- a/lib/Redis.pm +++ b/lib/Redis.pm @@ -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<< >> diff --git a/t/01-Redis.t b/t/01-Redis.t index 1e6092c..06895a7 100755 --- a/t/01-Redis.t +++ b/t/01-Redis.t @@ -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' ); -- 2.20.1