diff options
author | dormando <dormando@rydia.net> | 2011-09-27 00:57:06 -0700 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2011-09-27 00:57:06 -0700 |
commit | d87f568a95ed1abe468188476fa5ed9288799223 (patch) | |
tree | ae6717e84ccc88d5869bf9c95b225c3f3eb80543 /t/binary.t | |
parent | 51c8f31fc709d06c479de88bdc5e14e757faabc5 (diff) | |
download | memcached-d87f568a95ed1abe468188476fa5ed9288799223.tar.gz |
Backport binary TOUCH/GAT/GATQ commands
Taken from the 1.6 branch, partly written by Trond. I hope the CAS handling is
correct.
Diffstat (limited to 't/binary.t')
-rwxr-xr-x | t/binary.t | 43 |
1 files changed, 42 insertions, 1 deletions
@@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 3376; +use Test::More tests => 3435; use FindBin qw($Bin); use lib "$Bin/lib"; use MemcachedTest; @@ -41,6 +41,9 @@ use constant CMD_QUITQ => 0x17; use constant CMD_FLUSHQ => 0x18; use constant CMD_APPENDQ => 0x19; use constant CMD_PREPENDQ => 0x1A; +use constant CMD_TOUCH => 0x1C; +use constant CMD_GAT => 0x1D; +use constant CMD_GATQ => 0x1E; # REQ and RES formats are divided even though they currently share # the same format, since they _could_ differ in the future. @@ -237,6 +240,23 @@ is($mc->decr("x", 211), 0, "Floor is zero"); } } +# diag "Touch commands"; +{ + $mc->flush; + $mc->set("totouch", "toast", 0, 1); + my $res = $mc->touch("totouch", 10); + sleep 2; + $check->("totouch", 0, "toast"); + + $mc->set("totouch", "toast2", 0, 1); + my ($flags, $val, $i) = $mc->gat("totouch", 10); + is($val, "toast2", "GAT returned correct value"); + sleep 2; + $check->("totouch", 0, "toast2"); + + # Test miss as well +} + # diag "Silent set."; $mc->silent_mutation(::CMD_SETQ, 'silentset', 'silentsetval'); @@ -681,6 +701,27 @@ sub get_multi { return \%return; } +sub touch { + my $self = shift; + my ($key, $expire) = @_; + my $extra_header = pack "N", $expire; + my $cas = 0; + return $self->_do_command(::CMD_TOUCH, $key, '', $extra_header, $cas); +} + +sub gat { + my $self = shift; + my $key = shift; + my $expire = shift; + my $extra_header = pack "N", $expire; + my ($rv, $cas) = $self->_do_command(::CMD_GAT, $key, '', $extra_header); + + my $header = substr $rv, 0, 4, ''; + my $flags = unpack("N", $header); + + return ($flags, $rv, $cas); +} + sub version { my $self = shift; return $self->_do_command(::CMD_VERSION, '', ''); |