Reviewers: ,

Description:
I have attached a patch which allows obtaining the most recent protocol
result (eg. NOT_FOUND etc) for non-get commands.

This is useful if you eg. want to distinguish between NOT_FOUND and some
other error (eg. lost connection, protocol error etc.), or different set
fails (eg. size too big etc.)

Patch is created against svn trunk

Please review this at http://codereview.appspot.com/22052

Affected files:
  lib/Cache/Memcached.pm


Index: lib/Cache/Memcached.pm
===================================================================
--- lib/Cache/Memcached.pm      (revision 805)
+++ lib/Cache/Memcached.pm      (working copy)
@@ -25,6 +25,7 @@
     bucketcount _single_sock _stime
     connect_timeout cb_connect_fail
     parser_class
+    last_res
 };

 # flag definitions
@@ -86,6 +87,12 @@
     return $self;
 }

+sub last_res {
+    my Cache::Memcached $self = shift;
+
+    return $self->{last_res};
+}
+
 sub set_pref_ip {
     my Cache::Memcached $self = shift;
     $self->{'pref_ip'} = shift;
@@ -341,6 +348,8 @@
     my $res;
     my ($ret, $offset) = (undef, 0);

+    $self->{last_res} = undef;
+
     $check_complete ||= sub {
         return (rindex($ret, "\r\n") + 2 == length($ret));
     };
@@ -401,6 +410,9 @@
         return undef;
     }

+    $self->{last_res} = $ret;
+    $self->{last_res} =~ s/\r\n$//;
+
     return $ret;
 }

@@ -1093,6 +1105,16 @@
 values are capped at 0.  If server value is 1, a decrement of 2
 returns 0, not -1.

+=item C<last_res>
+
+$memd->last_res
+
+This method returns the status string of the last operation except for get(s).
+This allows you, for instance, to differentiate between C<NOT_FOUND> and a
+protocol error. The trailing \r\n has already been removed. See the
+memcached protocol docs for possible return values for each command:
+L<http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt>
+
 =item C<stats>

 $memd->stats([$keys]);


Reply via email to