[PATCH 2/2] Cache::Memcached: rewrite flush_all to not use run_command().

Tomash Brechko tomash.brechko at gmail.com
Fri Nov 9 15:05:53 UTC 2007


This patch also adds <time> optional parameter handling, as well as
'noreply' in void context.
---
 trunk/api/perl/lib/Cache/Memcached.pm |   11 +++++++++--
 trunk/api/perl/t/04_noreply.t         |    2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/trunk/api/perl/lib/Cache/Memcached.pm b/trunk/api/perl/lib/Cache/Memcached.pm
index 757575b..62bf609 100644
--- a/trunk/api/perl/lib/Cache/Memcached.pm
+++ b/trunk/api/perl/lib/Cache/Memcached.pm
@@ -788,14 +788,21 @@ sub _hashfunc {
 
 sub flush_all {
     my Cache::Memcached $self = shift;
+    my ($time) = @_;
 
     my $success = 1;
 
+    my @params;
+    push @params, $time if defined $time;
+    my $noreply = not defined wantarray;
+    push @params, "noreply" if $noreply;
+
+    my $line = "flush_all @params\r\n";
     my @hosts = @{$self->{'buckets'}};
     foreach my $host (@hosts) {
         my $sock = $self->sock_to_host($host);
-        my @res = $self->run_command($sock, "flush_all\r\n");
-        $success = 0 unless (@res);
+        my $res = _write_and_read($self, $sock, $line, undef, $noreply);
+        $success = 0 unless ($noreply or $res eq "OK\r\n");
     }
 
     return $success;
diff --git a/trunk/api/perl/t/04_noreply.t b/trunk/api/perl/t/04_noreply.t
index 26ff120..378422e 100644
--- a/trunk/api/perl/t/04_noreply.t
+++ b/trunk/api/perl/t/04_noreply.t
@@ -25,6 +25,8 @@ isa_ok($memd, 'Cache::Memcached');
 
 use constant count => 30;
 
+$memd->flush_all;
+
 $memd->add("key", "add");
 is($memd->get("key"), "add");
 
-- 
1.5.3.5.529.ge3d6d


More information about the memcached mailing list