1 2function mcp_config_pools() 3 local b1 = mcp.backend('b1', '127.0.0.1', 12091) 4 return mcp.pool({b1}) 5end 6 7function mcp_config_routes(p) 8 local setfg = mcp.funcgen_new() 9 local sh = setfg:new_handle(p) 10 setfg:ready({ f = function(rctx) 11 return function(r) 12 local k = r:key() 13 14 if k == "setints" then 15 print("FKEY:", k) 16 local flags = r:token_int(3) 17 local ttl = r:token_int(4) 18 local bytes = r:token_int(5) 19 flags = flags + ttl + bytes 20 r:token(3, flags) 21 return rctx:enqueue_and_wait(r, sh) 22 end 23 end 24 end}) 25 26 local mgfg = mcp.funcgen_new() 27 local h = mgfg:new_handle(p) 28 mgfg:ready({ f = function(rctx) 29 return function(r) 30 local k = r:key() 31 32 if k == "add1" then 33 r:flag_add("F") 34 return rctx:enqueue_and_wait(r, h) 35 elseif k == "addstr" then 36 r:flag_add("F", "1234") 37 return rctx:enqueue_and_wait(r, h) 38 elseif k == "addnum" then 39 r:flag_add("F", 5678) 40 return rctx:enqueue_and_wait(r, h) 41 elseif k == "addexist" then 42 if r:flag_add("O", "overwrite") then 43 return "SERVER_ERROR flag overwritten" 44 else 45 return "HD\r\n" 46 end 47 end 48 49 if k == "set1" then 50 r:flag_set("F") 51 return rctx:enqueue_and_wait(r, h) 52 elseif k == "setstr" then 53 r:flag_set("F", "4321") 54 return rctx:enqueue_and_wait(r, h) 55 elseif k == "setnum" then 56 r:flag_set("F", 8765) 57 return rctx:enqueue_and_wait(r, h) 58 elseif k == "setexist" then 59 if r:flag_set("O", "overwrite") then 60 return rctx:enqueue_and_wait(r, h) 61 else 62 return "HD\r\n" 63 end 64 elseif k == "setflag" then 65 -- technically protocol invalid but should work. 66 if r:flag_set("O") then 67 return rctx:enqueue_and_wait(r, h) 68 else 69 return "HD\r\n" 70 end 71 end 72 73 -- don't need full set of tests anymore since this function reuses 74 -- the code for add/set. 75 if k == "repl1" then 76 r:flag_replace("F", "O", "foo") 77 return rctx:enqueue_and_wait(r, h) 78 elseif k == "repl2" then 79 r:flag_replace("F", "O") 80 return rctx:enqueue_and_wait(r, h) 81 end 82 83 if k == "del1" then 84 r:flag_del("O") 85 return rctx:enqueue_and_wait(r, h) 86 end 87 88 if k == "fint" then 89 -- avoids creating string junk if we only need to treat this 90 -- token as an integer. 91 local found, token = r:flag_token_int("F") 92 if type(token) ~= "number" then 93 error("token wasn't converted to a number") 94 end 95 token = token * 10 + 1 96 r:flag_set("F", token) 97 return rctx:enqueue_and_wait(r, h) 98 end 99 end 100 end}) 101 102 mcp.attach(mcp.CMD_MG, mgfg) 103 mcp.attach(mcp.CMD_SET, setfg) 104 -- TODO: test MS as well to ensure it doesn't eat the value line 105end 106