summaryrefslogtreecommitdiff
path: root/proxy_lua.c
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2022-07-29 18:38:15 -0700
committerdormando <dormando@rydia.net>2022-08-03 11:53:29 -0700
commit2389436317fe9d74d390d0adfe4a2679c693375e (patch)
treebd49936324871903bf3c2f2a10014e174638f41c /proxy_lua.c
parent4f07a597bbd0367d6458ed4c65f47ec9ca3910cd (diff)
downloadmemcached-2389436317fe9d74d390d0adfe4a2679c693375e.tar.gz
proxy: mcp.request improvements
- errors if a string value is missing the "\r\n" terminator - properly uses a value from a response object - allows passing in a request object for the value as well - also adds r:vlen() for recovering the value length of a response think this still needs r:flags() or similar?
Diffstat (limited to 'proxy_lua.c')
-rw-r--r--proxy_lua.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/proxy_lua.c b/proxy_lua.c
index 5f5707c..383f747 100644
--- a/proxy_lua.c
+++ b/proxy_lua.c
@@ -32,6 +32,23 @@ static int mcplib_response_hit(lua_State *L) {
return 1;
}
+// Caller needs to discern if a vlen is 0 because of a failed response or an
+// OK response that was actually zero. So we always return an integer value
+// here.
+static int mcplib_response_vlen(lua_State *L) {
+ mcp_resp_t *r = luaL_checkudata(L, -1, "mcp.response");
+
+ // We do remove the "\r\n" from the value length, so if you're actually
+ // processing the value nothing breaks.
+ if (r->resp.vlen >= 2) {
+ lua_pushinteger(L, r->resp.vlen-2);
+ } else {
+ lua_pushinteger(L, 0);
+ }
+
+ return 1;
+}
+
static int mcplib_response_gc(lua_State *L) {
mcp_resp_t *r = luaL_checkudata(L, -1, "mcp.response");
@@ -773,6 +790,7 @@ int proxy_register_libs(LIBEVENT_THREAD *t, void *ctx) {
const struct luaL_Reg mcplib_response_m[] = {
{"ok", mcplib_response_ok},
{"hit", mcplib_response_hit},
+ {"vlen", mcplib_response_vlen},
{"__gc", mcplib_response_gc},
{NULL, NULL}
};