summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2022-08-01 16:51:50 -0700
committerdormando <dormando@rydia.net>2022-08-03 11:53:33 -0700
commit71c7d8604713104fd9b6ad54c28dbdaa047251d8 (patch)
tree0c7045abb3bb5d42ed46a0e282b52d91dde92b83
parent2520054b152863babbc01cd5d7bab5d5f7705667 (diff)
downloadmemcached-71c7d8604713104fd9b6ad54c28dbdaa047251d8.tar.gz
proxy: mcp.response code and rline API
Adds resp:code(), which returns code you can compare with mcp.MCMC_CODE_* Adds resp:line(), which returns the raw response line after the command. This can be used in lua while the flag/token API is missing for the response object.
-rw-r--r--proxy_lua.c34
-rw-r--r--t/startfile.lua15
2 files changed, 49 insertions, 0 deletions
diff --git a/proxy_lua.c b/proxy_lua.c
index c01d327..d611a45 100644
--- a/proxy_lua.c
+++ b/proxy_lua.c
@@ -49,6 +49,28 @@ static int mcplib_response_vlen(lua_State *L) {
return 1;
}
+// Refer to MCMC_CODE_* defines.
+static int mcplib_response_code(lua_State *L) {
+ mcp_resp_t *r = luaL_checkudata(L, -1, "mcp.response");
+
+ lua_pushinteger(L, r->resp.code);
+
+ return 1;
+}
+
+// Get the unparsed response line for handling in lua.
+static int mcplib_response_line(lua_State *L) {
+ mcp_resp_t *r = luaL_checkudata(L, -1, "mcp.response");
+
+ if (r->resp.rline != NULL) {
+ lua_pushlstring(L, r->resp.rline, r->resp.rlen);
+ } else {
+ lua_pushnil(L);
+ }
+
+ return 1;
+}
+
static int mcplib_response_gc(lua_State *L) {
mcp_resp_t *r = luaL_checkudata(L, -1, "mcp.response");
@@ -754,6 +776,16 @@ static void proxy_register_defines(lua_State *L) {
lua_pushinteger(L, x); \
lua_setfield(L, -2, #x);
+ X(MCMC_CODE_STORED);
+ X(MCMC_CODE_EXISTS);
+ X(MCMC_CODE_DELETED);
+ X(MCMC_CODE_TOUCHED);
+ X(MCMC_CODE_VERSION);
+ X(MCMC_CODE_NOT_FOUND);
+ X(MCMC_CODE_NOT_STORED);
+ X(MCMC_CODE_OK);
+ X(MCMC_CODE_NOP);
+ X(MCMC_CODE_MISS);
X(P_OK);
X(CMD_ANY);
X(CMD_ANY_STORAGE);
@@ -792,6 +824,8 @@ int proxy_register_libs(LIBEVENT_THREAD *t, void *ctx) {
{"ok", mcplib_response_ok},
{"hit", mcplib_response_hit},
{"vlen", mcplib_response_vlen},
+ {"code", mcplib_response_code},
+ {"line", mcplib_response_line},
{"__gc", mcplib_response_gc},
{NULL, NULL}
};
diff --git a/t/startfile.lua b/t/startfile.lua
index 6abaa75..e5dd606 100644
--- a/t/startfile.lua
+++ b/t/startfile.lua
@@ -172,6 +172,20 @@ function meta_get_factory(zones, local_zone)
end
end
+function meta_set_factory(zones, local_zone)
+ local near_zone = zones[local_zone]
+ -- in this test function we only talk to the local zone.
+ return function(r)
+ local res = near_zone(r)
+ if res:code() == mcp.MCMC_CODE_NOT_FOUND then
+ print("got meta NF response")
+ end
+ print("meta response line: " .. res:line())
+
+ return res
+ end
+end
+
-- SET's to main zone, issues deletes to far zones.
function setinvalidate_factory(zones, local_zone)
local near_zone = zones[local_zone]
@@ -302,6 +316,7 @@ function mcp_config_routes(main_zones)
-- prefix or something)
map[mcp.CMD_ADD] = failover_factory(z, my_zone)
map[mcp.CMD_MG] = meta_get_factory(z, my_zone)
+ map[mcp.CMD_MS] = meta_set_factory(z, my_zone)
prefixes[pfx] = command_factory(map, failover)
end