diff options
author | Dustin Sallings <dustin@spy.net> | 2009-11-24 15:03:35 -0800 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2009-11-26 21:45:13 -0800 |
commit | 62a0cf9e0ba4592870b5e86e5cb2f79e1a78f9ba (patch) | |
tree | 820bb631321e7c16af74a0234ba5c11c1023a0a5 | |
parent | 6436b96cc4d78fec0ceb839e2d1cdf455c7385bd (diff) | |
download | memcached-1.4.4.tar.gz |
Allow noreply mixed with 0 delay.1.4.4
-rw-r--r-- | memcached.c | 12 | ||||
-rw-r--r-- | t/issue_108.t | 9 | ||||
-rw-r--r-- | t/issue_3.t | 11 |
3 files changed, 25 insertions, 7 deletions
diff --git a/memcached.c b/memcached.c index 3428cc6..537fc86 100644 --- a/memcached.c +++ b/memcached.c @@ -2882,15 +2882,19 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken assert(c != NULL); - if (ntokens == 4) { - if (strcmp(tokens[KEY_TOKEN+1].value, "0") != 0 - && !set_noreply_maybe(c, tokens, ntokens)) { + if (ntokens > 3) { + bool hold_is_zero = strcmp(tokens[KEY_TOKEN+1].value, "0") == 0; + bool sets_noreply = set_noreply_maybe(c, tokens, ntokens); + bool valid = (ntokens == 4 && (hold_is_zero || sets_noreply)) + || (ntokens == 5 && hold_is_zero && sets_noreply); + if (!valid) { out_string(c, "CLIENT_ERROR bad command line format. " "Usage: delete <key> [noreply]"); return; } } + key = tokens[KEY_TOKEN].value; nkey = tokens[KEY_TOKEN].length; @@ -2994,7 +2998,7 @@ static void process_command(conn *c, char *command) { process_arithmetic_command(c, tokens, ntokens, 0); - } else if (ntokens >= 3 && ntokens <= 4 && (strcmp(tokens[COMMAND_TOKEN].value, "delete") == 0)) { + } else if (ntokens >= 3 && ntokens <= 5 && (strcmp(tokens[COMMAND_TOKEN].value, "delete") == 0)) { process_delete_command(c, tokens, ntokens); diff --git a/t/issue_108.t b/t/issue_108.t index c370588..07a78b7 100644 --- a/t/issue_108.t +++ b/t/issue_108.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use Test::More tests => 3; +use Test::More tests => 4; use FindBin qw($Bin); use lib "$Bin/lib"; use MemcachedTest; @@ -18,3 +18,10 @@ is (scalar <$sock>, "DELETED\r\n", "Properly deleted with 0"); print $sock "add $key 0 0 1\r\nx\r\n"; is (scalar <$sock>, "STORED\r\n", "Added again a key"); + +print $sock "delete $key 0 noreply\r\n"; +# will not reply, but a subsequent add will succeed + +print $sock "add $key 0 0 1\r\nx\r\n"; +is (scalar <$sock>, "STORED\r\n", "Add succeeded after quiet deletion."); + diff --git a/t/issue_3.t b/t/issue_3.t index 23df528..66aaf16 100644 --- a/t/issue_3.t +++ b/t/issue_3.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; -use Test::More tests => 7; +use Test::More tests => 8; use FindBin qw($Bin); use lib "$Bin/lib"; use MemcachedTest; @@ -17,8 +17,15 @@ print $sock "delete $key 10\r\n"; is (scalar <$sock>, "CLIENT_ERROR bad command line format." . " Usage: delete <key> [noreply]\r\n", "invalid delete"); +print $sock "add $key 0 0 1\r\nx\r\n"; +is (scalar <$sock>, "STORED\r\n", "Add before a broken delete."); + print $sock "delete $key 10 noreply\r\n"; -is (scalar <$sock>, "ERROR\r\n", "Even more invalid delete"); +# Does not reply +# is (scalar <$sock>, "ERROR\r\n", "Even more invalid delete"); + +print $sock "add $key 0 0 1\r\nx\r\n"; +is (scalar <$sock>, "NOT_STORED\r\n", "Failed to add after failed silent delete."); print $sock "delete $key noreply\r\n"; # Will not reply, so let's do a set and check that. |