[memcached] bradfitz, r357: incrdecr tests and new protocol note
commits at code.sixapart.com
commits at code.sixapart.com
Mon Sep 4 21:16:19 UTC 2006
incrdecr tests and new protocol note
U trunk/server/doc/protocol.txt
U trunk/server/test/incrdecr.t
Modified: trunk/server/doc/protocol.txt
===================================================================
--- trunk/server/doc/protocol.txt 2006-09-04 21:04:02 UTC (rev 356)
+++ trunk/server/doc/protocol.txt 2006-09-04 21:16:19 UTC (rev 357)
@@ -268,7 +268,7 @@
- <value> is the amount by which the client wants to increase/decrease
the item. It is a decimal representation of a 32-bit unsigned integer.
-The response will be one of:
+The response will be one of:
- "NOT_FOUND\r\n" to indicate the item with this value was not found
@@ -279,6 +279,10 @@
to decrease the value below 0, the new value will be 0. Overflow in
the "incr" command is not checked.
+Note also that decrementing a number such that it loses length isn't
+guaranteed to decrement its returned length. The number MAY be
+space-padded at the end, but this is purely an implementation
+optimization, so you also shouldn't rely on that.
Statistics
----------
Modified: trunk/server/test/incrdecr.t
===================================================================
--- trunk/server/test/incrdecr.t 2006-09-04 21:04:02 UTC (rev 356)
+++ trunk/server/test/incrdecr.t 2006-09-04 21:16:19 UTC (rev 357)
@@ -1,7 +1,7 @@
#!/usr/bin/perl
use strict;
-use Test::More skip_all => "Tests not written."; # tests => 1
+use Test::More tests => 13;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
@@ -9,3 +9,36 @@
my $server = new_memcached();
my $sock = $server->sock;
+print $sock "set num 0 0 1\r\n1\r\n";
+is(scalar <$sock>, "STORED\r\n", "stored num");
+mem_get_is($sock, "num", 1, "stored 1");
+
+print $sock "incr num 1\r\n";
+is(scalar <$sock>, "2\r\n", "+ 1 = 2");
+mem_get_is($sock, "num", 2);
+
+print $sock "incr num 8\r\n";
+is(scalar <$sock>, "10\r\n", "+ 8 = 10");
+mem_get_is($sock, "num", 10);
+
+print $sock "decr num 1\r\n";
+is(scalar <$sock>, "9\r\n", "- 1 = 9");
+
+print $sock "decr num 9\r\n";
+is(scalar <$sock>, "0\r\n", "- 9 = 0");
+
+print $sock "decr num 5\r\n";
+is(scalar <$sock>, "0\r\n", "- 5 = 0");
+
+print $sock "decr bogus 5\r\n";
+is(scalar <$sock>, "NOT_FOUND\r\n", "can't decr bogus key");
+
+print $sock "decr incr 5\r\n";
+is(scalar <$sock>, "NOT_FOUND\r\n", "can't incr bogus key");
+
+print $sock "set text 0 0 2\r\nhi\r\n";
+is(scalar <$sock>, "STORED\r\n", "stored text");
+print $sock "incr text 1\r\n";
+is(scalar <$sock>, "1\r\n", "hi - 1 = 0");
+
+
More information about the memcached-commits
mailing list