summaryrefslogtreecommitdiff
path: root/proxy_lua.c
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 /proxy_lua.c
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.
Diffstat (limited to 'proxy_lua.c')
-rw-r--r--proxy_lua.c34
1 files changed, 34 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}
};