Skip to content

Commit

Permalink
Allow noreply mixed with 0 delay.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin authored and dormando committed Nov 27, 2009
1 parent 6436b96 commit 62a0cf9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
12 changes: 8 additions & 4 deletions memcached.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
9 changes: 8 additions & 1 deletion 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;
Expand All @@ -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.");

11 changes: 9 additions & 2 deletions 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;
Expand All @@ -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.
Expand Down

0 comments on commit 62a0cf9

Please sign in to comment.