Honour noreply flag for set command

Sun, 01 Aug 2010 12:16:06 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 01 Aug 2010 12:16:06 +0100
changeset 12
fb941ed514c6
parent 11
85c18da60925
child 13
db66a09dc0b6

Honour noreply flag for set command

mooncached.lua file | annotate | diff | comparison | revisions
--- a/mooncached.lua	Sun Aug 01 01:23:32 2010 +0100
+++ b/mooncached.lua	Sun Aug 01 12:16:06 2010 +0100
@@ -35,7 +35,11 @@
 	local key, flags, exptime, bytes, reply = params:match("(%S+) (%d+) (%d+) (%d+) ?(.*)$");
 	flags, exptime, bytes, reply = tonumber(flags), tonumber(exptime), tonumber(bytes), reply ~= "noreply";
 	if not (flags and exptime and bytes) then
-		return false, "Invalid parameter(s)";
+		if reply then
+			return false, "Invalid parameter(s)";
+		else
+			return nil;
+		end
 	end
 	conn:set_mode("*a");
 	local received_count, received_buffer = 0, {};
@@ -46,10 +50,12 @@
 		if received_count >= bytes then
 			received_buffer = table.concat(received_buffer);
 			local ok, err = cache:set(key, flags, exptime, received_buffer:sub(1,bytes));
-			if ok then
-				conn:send("STORED\r\n");
-			else
-				conn:send("SERVER_ERROR "..(err or "Unknown error").."\r\n");
+			if reply then
+				if ok then
+					conn:send("STORED\r\n");
+				else
+					conn:send("SERVER_ERROR "..(err or "Unknown error").."\r\n");
+				end
 			end
 			conn:setlistener(memcached_listener);
 			conn:set_mode("*l");

mercurial