pax_global_header00006660000000000000000000000064120540566760014525gustar00rootroot0000000000000052 comment=d6e69448700a37e62f3a6e50361b9a325d1de153 lua-resty-memcached-master/000077500000000000000000000000001205405667600162135ustar00rootroot00000000000000lua-resty-memcached-master/.gitignore000066400000000000000000000000531205405667600202010ustar00rootroot00000000000000*.swp *.swo *~ go t/servroot/ reindex *.t_ lua-resty-memcached-master/Makefile000066400000000000000000000006511205405667600176550ustar00rootroot00000000000000OPENRESTY_PREFIX=/usr/local/openresty-debug PREFIX ?= /usr/local LUA_INCLUDE_DIR ?= $(PREFIX)/include LUA_LIB_DIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION) INSTALL ?= install .PHONY: all test install all: ; install: all $(INSTALL) -d $(DESTDIR)/$(LUA_LIB_DIR)/resty $(INSTALL) lib/resty/*.lua $(DESTDIR)/$(LUA_LIB_DIR)/resty test: all PATH=$(OPENRESTY_PREFIX)/nginx/sbin:$$PATH prove -I../test-nginx/lib -r t lua-resty-memcached-master/README.markdown000066400000000000000000000361401205405667600207200ustar00rootroot00000000000000Name ==== lua-resty-memcached - Lua memcached client driver for the ngx_lua based on the cosocket API Status ====== This library is considered production ready. Description =========== This Lua library is a memcached client driver for the ngx_lua nginx module: http://wiki.nginx.org/HttpLuaModule This Lua library takes advantage of ngx_lua's cosocket API, which ensures 100% nonblocking behavior. Note that at least [ngx_lua 0.5.0rc29](https://github.com/chaoslawful/lua-nginx-module/tags) or [ngx_openresty 1.0.15.7](http://openresty.org/#Download) is required. Synopsis ======== lua_package_path "/path/to/lua-resty-memcached/lib/?.lua;;"; server { location /test { content_by_lua ' local memcached = require "resty.memcached" local memc, err = memcached:new() if not memc then ngx.say("failed to instantiate memc: ", err) return end memc:set_timeout(1000) -- 1 sec -- or connect to a unix domain socket file listened -- by a memcached server: -- local ok, err = memc:connect("unix:/path/to/memc.sock") local ok, err = memc:connect("127.0.0.1", 11211) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) -- put it into the connection pool of size 100, -- with 0 idle timeout memc:set_keepalive(0, 100) -- or just close the connection right away: -- local ok, err = memc:close() -- if not ok then -- ngx.say("failed to close: ", err) -- return -- end '; } } Methods ======= The `key` argument provided in the following methods will be automatically escaped according to the URI escaping rules before sending to the memcached server. new --- `syntax: memc, err = memcached:new(opts?)` Creates a memcached object. In case of failures, returns `nil` and a string describing the error. It accepts an optional `opts` table argument. The following options are supported: * `key_transform` : an array table containing two functions for escaping and unescaping the : memcached keys, respectively. By default, : the memcached keys will be escaped and unescaped as URI components, that is memached:new{ key_transform = { ngx.escape_uri, ngx.unescape_uri } } connect ------- `syntax: ok, err = memc:connect(host, port)` `syntax: ok, err = memc:connect("unix:/path/to/unix.sock")` Attempts to connect to the remote host and port that the memcached server is listening to or a local unix domain socket file listened by the memcached server. Before actually resolving the host name and connecting to the remote backend, this method will always look up the connection pool for matched idle connections created by previous calls of this method. set --- `syntax: ok, err = memc:set(key, value, exptime, flags)` Inserts an entry into memcached unconditionally. If the key already exists, overrides it. The `value` argument could also be a Lua table holding multiple Lua strings that are supposed to be concatenated as a whole (without any delimiters). For example, memc:set("dog", {"a ", {"kind of"}, " animal"}) is functionally equivalent to memc:set("dog", "a kind of animal") The `exptime` parameter is optional, defaults to `0`. The `flags` parameter is optional, defaults to `0`. set_timeout ---------- `syntax: memc:set_timeout(time)` Sets the timeout (in ms) protection for subsequent operations, including the `connect` method. set_keepalive ------------ `syntax: ok, err = memc:set_keepalive(max_idle_timeout, pool_size)` Puts the current memcached connection immediately into the ngx_lua cosocket connection pool. You can specify the max idle timeout (in ms) when the connection is in the pool and the maximal size of the pool every nginx worker process. In case of success, returns `1`. In case of errors, returns `nil` with a string describing the error. Only call this method in the place you would have called the `close` method instead. Calling this method will immediately turn the current memcached object into the `closed` state. Any subsequent operations other than `connect()` on the current objet will return the `closed` error. get_reused_times ---------------- `syntax: times, err = memc:get_reused_times()` This method returns the (successfully) reused times for the current connection. In case of error, it returns `nil` and a string describing the error. If the current connection does not come from the built-in connection pool, then this method always returns `0`, that is, the connection has never been reused (yet). If the connection comes from the connection pool, then the return value is always non-zero. So this method can also be used to determine if the current connection comes from the pool. close ----- `syntax: ok, err = memc:close()` Closes the current memcached connection and returns the status. In case of success, returns `1`. In case of errors, returns `nil` with a string describing the error. add --- `syntax: ok, err = memc:add(key, value, exptime, flags)` Inserts an entry into memcached if and only if the key does not exist. The `value` argument could also be a Lua table holding multiple Lua strings that are supposed to be concatenated as a whole (without any delimiters). For example, memc:add("dog", {"a ", {"kind of"}, " animal"}) is functionally equivalent to memc:add("dog", "a kind of animal") The `exptime` parameter is optional, defaults to `0`. The `flags` parameter is optional, defaults to `0`. In case of success, returns `1`. In case of errors, returns `nil` with a string describing the error. replace ------- `syntax: ok, err = memc:replace(key, value, exptime, flags)` Inserts an entry into memcached if and only if the key does exist. The `value` argument could also be a Lua table holding multiple Lua strings that are supposed to be concatenated as a whole (without any delimiters). For example, memc:replace("dog", {"a ", {"kind of"}, " animal"}) is functionally equivalent to memc:replace("dog", "a kind of animal") The `exptime` parameter is optional, defaults to `0`. The `flags` parameter is optional, defaults to `0`. In case of success, returns `1`. In case of errors, returns `nil` with a string describing the error. append ------ `syntax: ok, err = memc:append(key, value, exptime, flags)` Appends the value to an entry with the same key that already exists in memcached. The `value` argument could also be a Lua table holding multiple Lua strings that are supposed to be concatenated as a whole (without any delimiters). For example, memc:append("dog", {"a ", {"kind of"}, " animal"}) is functionally equivalent to memc:append("dog", "a kind of animal") The `exptime` parameter is optional, defaults to `0`. The `flags` parameter is optional, defaults to `0`. In case of success, returns `1`. In case of errors, returns `nil` with a string describing the error. prepend ------- `syntax: ok, err = memc:prepend(key, value, exptime, flags)` Prepends the value to an entry with the same key that already exists in memcached. The `value` argument could also be a Lua table holding multiple Lua strings that are supposed to be concatenated as a whole (without any delimiters). For example, memc:prepend("dog", {"a ", {"kind of"}, " animal"}) is functionally equivalent to memc:prepend("dog", "a kind of animal") The `exptime` parameter is optional, defaults to `0`. The `flags` parameter is optional, defaults to `0`. In case of success, returns `1`. In case of errors, returns `nil` with a string describing the error. get --- `syntax: value, flags, err = memc:get(key)` `syntax: results, err = memc:get(keys)` Get a single entry or multiple entries in the memcached server via a single key or a talbe of keys. Let us first discuss the case When the key is a single string. The key's value and associated flags value will be returned if the entry is found and no error happens. In case of errors, `nil` values will be turned for `value` and `flags` and a 3rd (string) value will also be returned for describing the error. If the entry is not found, then three `nil` values will be returned. Then let us discuss the case when the a Lua table of multiple keys are provided. In this case, a Lua table holding the key-result pairs will be always returned in case of success. Each value corresponding each key in the table is also a table holding two values, the key's value and the key's flags. If a key does not exist, then there is no responding entries in the `results` table. In case of errors, `nil` will be returned, and the second return value will be a string describing the error. gets ---- `syntax: value, flags, cas_unique, err = memc:gets(key)` `syntax: results, err = memc:gets(keys)` Just like the `get` method, but will also return the CAS unique value associated with the entry in addition to the key's value and flags. This method is usually used together with the `cas` method. cas --- `syntax: ok, err = memc:cas(key, value, cas_unique, exptime?, flags?)` Just like the `set` method but does a check and set operation, which means "store this data but only if no one else has updated since I last fetched it." The `cas_unique` argument can be obtained from the `gets` method. flush_all --------- `syntax: ok, err = memc:flush_all(time?)` Flushes (or invalidates) all the existing entries in the memcached server immediately (by default) or after the expiration specified by the `time` argument (in seconds). In case of success, returns `1`. In case of errors, returns `nil` with a string describing the error. delete ------ `syntax: ok, err = memc:delete(key)` Deletes the key from memcached immediately. The key to be deleted must already exist in memcached. In case of success, returns `1`. In case of errors, returns `nil` with a string describing the error. incr ---- `syntax: new_value, err = memc:incr(key, delta)` Increments the value of the specified key by the integer value specified in the `delta` argument. Returns the new value after incrementation in success, and `nil` with a string describing the error in case of failures. decr ---- `syntax: new_value, err = memc:decr(key, value)` Decrements the value of the specified key by the integer value specified in the `delta` argument. Returns the new value after decrementation in success, and `nil` with a string describing the error in case of failures. stats ----- `syntax: lines, err = memc:stats(args?)` Returns memcached server statistics information with an optional `args` argument. In case of success, this method returns a lua table holding all of the lines of the output; in case of failures, it returns `nil` with a string describing the error. If the `args` argument is omitted, general server statistics is returned. Possible `args` argument values are `items`, `sizes`, `slabs`, among others. version ------- `syntax: version, err = memc:version(args?)` Returns the server version number, like `1.2.8`. In case of error, it returns `nil` with a string describing the error. quit ---- `syntax: ok, err = memc:quit()` Tells the server to close the current memcached connection. Returns `1` in case of success and `nil` other wise. In case of failures, another string value will also be returned to describe the error. Generally you can just directly call the `close` method to achieve the same effect. verbosity --------- `syntax: ok, err = memc:verbosity(level)` Sets the verbosity level used by the memcached server. The `level` argument should be given integers only. Returns `1` in case of success and `nil` other wise. In case of failures, another string value will also be returned to describe the error. Limitations =========== * This library cannot be used in code contexts like set_by_lua*, log_by_lua*, and header_filter_by_lua* where the ngx_lua cosocket API is not available. * The `resty.memcached` object instance cannot be stored in a Lua variable at the Lua module level, because it will then be shared by all the concurrent requests handled by the same nginx worker process (see http://wiki.nginx.org/HttpLuaModule#Data_Sharing_within_an_Nginx_Worker ) and result in bad race conditions when concurrent requests are trying to use the same `resty.memcached` instance. You should always initiate `resty.memcached` objects in function local variables or in the `ngx.ctx` table. These places all have their own data copies for each request. TODO ==== * implement the memcached pipelining API. * implement the UDP part of the memcached ascii protocol. Author ====== Yichun "agentzh" Zhang (章亦春) Copyright and License ===================== This module is licensed under the BSD license. Copyright (C) 2012, by Yichun "agentzh" Zhang (章亦春) . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. See Also ======== * the ngx_lua module: http://wiki.nginx.org/HttpLuaModule * the memcached wired protocol specification: http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt * the [lua-resty-redis](https://github.com/agentzh/lua-resty-redis) library. * the [lua-resty-mysql](https://github.com/agentzh/lua-resty-mysql) library. lua-resty-memcached-master/lib/000077500000000000000000000000001205405667600167615ustar00rootroot00000000000000lua-resty-memcached-master/lib/resty/000077500000000000000000000000001205405667600201275ustar00rootroot00000000000000lua-resty-memcached-master/lib/resty/memcached.lua000066400000000000000000000311441205405667600225430ustar00rootroot00000000000000-- Copyright (C) 2012 Yichun Zhang (agentzh) local sub = string.sub local escape_uri = ngx.escape_uri local unescape_uri = ngx.unescape_uri local match = string.match local tcp = ngx.socket.tcp local strlen = string.len local insert = table.insert local concat = table.concat local setmetatable = setmetatable local type = type local error = error module(...) _VERSION = '0.10' local mt = { __index = _M } function new(self, opts) local sock, err = tcp() if not sock then return nil, err end local escape_key = escape_uri local unescape_key = unescape_uri if opts then local key_transform = opts.key_transform if key_transform then escape_key = key_transform[1] unescape_key = key_transform[2] if not escape_key or not unescape_key then return nil, "expecting key_transform = { escape, unescape } table" end end end return setmetatable({ sock = sock, escape_key = escape_key, unescape_key = unescape_key, }, mt) end function set_timeout(self, timeout) local sock = self.sock if not sock then return nil, "not initialized" end return sock:settimeout(timeout) end function connect(self, ...) local sock = self.sock if not sock then return nil, "not initialized" end return sock:connect(...) end local function _multi_get(self, keys) local sock = self.sock if not sock then return nil, "not initialized" end local nkeys = #keys if nkeys == 0 then return {}, nil end local escape_key = self.escape_key local cmd = {"get"} for i = 1, nkeys do insert(cmd, " ") insert(cmd, escape_key(keys[i])) end insert(cmd, "\r\n") -- print("multi get cmd: ", cmd) local bytes, err = sock:send(concat(cmd)) if not bytes then return nil, err end local unescape_key = self.unescape_key local results = {} while true do local line, err = sock:receive() if not line then return nil, err end if line == 'END' then break end local key, flags, len = match(line, '^VALUE (%S+) (%d+) (%d+)$') -- print("key: ", key, "len: ", len, ", flags: ", flags) if key then local data, err = sock:receive(len) if not data then return nil, err end results[unescape_key(key)] = {data, flags} data, err = sock:receive(2) -- discard the trailing CRLF if not data then return nil, err end end end return results end function get(self, key) if type(key) == "table" then return _multi_get(self, key) end local sock = self.sock if not sock then return nil, nil, "not initialized" end local cmd = {"get ", self.escape_key(key), "\r\n"} local bytes, err = sock:send(concat(cmd)) if not bytes then return nil, nil, "failed to send command: " .. (err or "") end local line, err = sock:receive() if not line then return nil, nil, "failed to receive 1st line: " .. (err or "") end if line == 'END' then return nil, nil, nil end local flags, len = match(line, '^VALUE %S+ (%d+) (%d+)$') if not flags then return nil, nil, "bad line: " .. line end -- print("len: ", len, ", flags: ", flags) local data, err = sock:receive(len) if not data then return nil, nil, "failed to receive data chunk: " .. (err or "") end line, err = sock:receive(2) -- discard the trailing CRLF if not line then return nil, nil, "failed to receive CRLF: " .. (err or "") end line, err = sock:receive() -- discard "END\r\n" if not line then return nil, nil, "failed to receive END CRLF: " .. (err or "") end return data, flags end local function _multi_gets(self, keys) local sock = self.sock if not sock then return nil, "not initialized" end local nkeys = #keys if nkeys == 0 then return {}, nil end local escape_key = self.escape_key local cmd = {"gets"} for i = 1, nkeys do insert(cmd, " ") insert(cmd, escape_key(keys[i])) end insert(cmd, "\r\n") -- print("multi get cmd: ", cmd) local bytes, err = sock:send(concat(cmd)) if not bytes then return nil, err end local unescape_key = self.unescape_key local results = {} while true do local line, err = sock:receive() if not line then return nil, err end if line == 'END' then break end local key, flags, len, cas_uniq = match(line, '^VALUE (%S+) (%d+) (%d+) (%d+)$') -- print("key: ", key, "len: ", len, ", flags: ", flags) if key then local data, err = sock:receive(len) if not data then return nil, err end results[unescape_key(key)] = {data, flags, cas_uniq} data, err = sock:receive(2) -- discard the trailing CRLF if not data then return nil, err end end end return results end function gets(self, key) if type(key) == "table" then return _multi_gets(self, key) end local sock = self.sock if not sock then return nil, nil, nil, "not initialized" end local cmd = {"gets ", self.escape_key(key), "\r\n"} local bytes, err = sock:send(concat(cmd)) if not bytes then return nil, nil, err end local line, err = sock:receive() if not line then return nil, nil, nil, err end if line == 'END' then return nil, nil, nil, nil end local flags, len, cas_uniq = match(line, '^VALUE %S+ (%d+) (%d+) (%d+)$') if not flags then return nil, nil, nil, line end -- print("len: ", len, ", flags: ", flags) local data, err = sock:receive(len) if not data then return nil, nil, nil, err end line, err = sock:receive(2) -- discard the trailing CRLF if not line then return nil, nil, nil, err end line, err = sock:receive() -- discard "END\r\n" if not line then return nil, nil, nil, err end return data, flags, cas_uniq end local function _expand_table(value) local segs = {} local nelems = #value for i = 1, nelems do local seg = value[i] if type(seg) == "table" then insert(segs, _expand_table(seg)) else insert(segs, seg) end end return concat(segs) end local function _store(self, cmd, key, value, exptime, flags) if not exptime then exptime = 0 end if not flags then flags = 0 end local sock = self.sock if not sock then return nil, "not initialized" end if type(value) == "table" then value = _expand_table(value) end local req = {cmd, " ", self.escape_key(key), " ", flags, " ", exptime, " ", strlen(value), "\r\n", value, "\r\n"} local bytes, err = sock:send(concat(req)) if not bytes then return nil, err end local data, err = sock:receive() if not data then return nil, err end if data == "STORED" then return 1 end return nil, data end function set(self, ...) return _store(self, "set", ...) end function add(self, ...) return _store(self, "add", ...) end function replace(self, ...) return _store(self, "replace", ...) end function append(self, ...) return _store(self, "append", ...) end function prepend(self, ...) return _store(self, "prepend", ...) end function cas(self, key, value, cas_uniq, exptime, flags) if not exptime then exptime = 0 end if not flags then flags = 0 end local sock = self.sock if not sock then return nil, "not initialized" end local req = {"cas ", self.escape_key(key), " ", flags, " ", exptime, " ", strlen(value), " ", cas_uniq, "\r\n", value, "\r\n"} -- local cjson = require "cjson" -- print("request: ", cjson.encode(req)) local bytes, err = sock:send(concat(req)) if not bytes then return nil, err end local line, err = sock:receive() if not line then return nil, err end -- print("response: [", line, "]") if line == "STORED" then return 1 end return nil, line end function delete(self, key) local sock = self.sock if not sock then return nil, "not initialized" end key = self.escape_key(key) local req = {"delete ", key, "\r\n"} local bytes, err = sock:send(concat(req)) if not bytes then return nil, err end local res, err = sock:receive() if not res then return nil, err end if res ~= 'DELETED' then return nil, res end return 1 end function set_keepalive(self, ...) local sock = self.sock if not sock then return nil, "not initialized" end return sock:setkeepalive(...) end function get_reused_times(self) local sock = self.sock if not sock then return nil, "not initialized" end return sock:getreusedtimes() end function flush_all(self, time) local sock = self.sock if not sock then return nil, "not initialized" end local req if time then req = concat({"flush_all ", time, "\r\n"}) else req = "flush_all\r\n" end local bytes, err = sock:send(req) if not bytes then return nil, err end local res, err = sock:receive() if not res then return nil, err end if res ~= 'OK' then return nil, res end return 1 end local function _incr_decr(self, cmd, key, value) local sock = self.sock if not sock then return nil, "not initialized" end local req = {cmd, " ", self.escape_key(key), " ", value, "\r\n"} local bytes, err = sock:send(concat(req)) if not bytes then return nil, err end local line, err = sock:receive() if not line then return nil, err end if not match(line, '^%d+$') then return nil, line end return line end function incr(self, key, value) return _incr_decr(self, "incr", key, value) end function decr(self, key, value) return _incr_decr(self, "decr", key, value) end function stats(self, args) local sock = self.sock if not sock then return nil, "not initialized" end local req if args then req = concat({"stats ", args, "\r\n"}) else req = "stats\r\n" end local bytes, err = sock:send(req) if not bytes then return nil, err end local lines = {} while true do local line, err = sock:receive() if not line then return nil, err end if line == 'END' then return lines, nil end if not match(line, "ERROR") then insert(lines, line) else return nil, line end end -- cannot reach here... return lines end function version(self) local sock = self.sock if not sock then return nil, "not initialized" end local bytes, err = sock:send("version\r\n") if not bytes then return nil, err end local line, err = sock:receive() if not line then return nil, err end local ver = match(line, "^VERSION (.+)$") if not ver then return nil, ver end return ver end function quit(self) local sock = self.sock if not sock then return nil, "not initialized" end local bytes, err = sock:send("quit\r\n") if not bytes then return nil, err end return 1 end function verbosity(self, level) local sock = self.sock if not sock then return nil, "not initialized" end local bytes, err = sock:send(concat({"verbosity ", level, "\r\n"})) if not bytes then return nil, err end local line, err = sock:receive() if not line then return nil, err end if line ~= 'OK' then return nil, line end return 1 end function close(self) local sock = self.sock if not sock then return nil, "not initialized" end return sock:close() end local class_mt = { -- to prevent use of casual module global variables __newindex = function (table, key, val) error('attempt to write to undeclared variable "' .. key .. '"') end } setmetatable(_M, class_mt) lua-resty-memcached-master/t/000077500000000000000000000000001205405667600164565ustar00rootroot00000000000000lua-resty-memcached-master/t/mock.t000066400000000000000000000023341205405667600175760ustar00rootroot00000000000000# vim:set ft= ts=4 sw=4 et: use Test::Nginx::Socket; use Cwd qw(cwd); repeat_each(2); plan tests => repeat_each() * (4 * blocks() + 1); my $pwd = cwd(); our $HttpConfig = qq{ lua_package_path "$pwd/lib/?.lua;;"; }; $ENV{TEST_NGINX_RESOLVER} = '8.8.8.8'; $ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211; no_long_string(); run_tests(); __DATA__ === TEST 1: fail to flush --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", 1921); if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end ngx.say("flush: ", ok); memc:close() '; } --- request GET /t --- tcp_listen: 1921 --- tcp_query_len: 11 --- tcp_query eval "flush_all\r\n" --- tcp_reply eval "SOME ERROR\r\n" --- response_body failed to flush all: SOME ERROR --- no_error_log [error] lua-resty-memcached-master/t/sanity.t000066400000000000000000001521401205405667600201550ustar00rootroot00000000000000# vim:set ft= ts=4 sw=4 et: use Test::Nginx::Socket; use Cwd qw(cwd); repeat_each(2); plan tests => repeat_each() * (3 * blocks() - 1); my $pwd = cwd(); our $HttpConfig = qq{ lua_package_path "$pwd/lib/?.lua;;"; }; $ENV{TEST_NGINX_RESOLVER} = '8.8.8.8'; $ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211; no_long_string(); run_tests(); __DATA__ === TEST 1: basic --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end for i = 1, 2 do local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ")") end memc:close() '; } --- request GET /t --- response_body dog: 32 (flags: 0) dog: 32 (flags: 0) --- no_error_log [error] === TEST 2: add an exsitent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local ok, err = memc:add("dog", 56) if not ok then ngx.say("failed to add dog: ", err) end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) memc:close() '; } --- request GET /t --- response_body failed to add dog: NOT_STORED dog: 32 --- no_error_log [error] === TEST 3: add a nonexistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:add("dog", 56) if not ok then ngx.say("failed to add dog: ", err) end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) memc:close() '; } --- request GET /t --- response_body dog: 56 --- no_error_log [error] === TEST 4: set an exsistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local ok, err = memc:set("dog", 56) if not ok then ngx.say("failed to set dog: ", err) return end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) memc:close() '; } --- request GET /t --- response_body dog: 56 --- no_error_log [error] === TEST 5: replace an exsistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local ok, err = memc:replace("dog", 56) if not ok then ngx.say("failed to replace dog: ", err) return end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) memc:close() '; } --- request GET /t --- response_body dog: 56 --- no_error_log [error] === TEST 6: replace a nonexsistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:replace("dog", 56) if not ok then ngx.say("failed to replace dog: ", err) end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) memc:close() '; } --- request GET /t --- response_body failed to replace dog: NOT_STORED dog not found --- no_error_log [error] === TEST 7: prepend to a nonexsistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:prepend("dog", 56) if not ok then ngx.say("failed to prepend to dog: ", err) end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) memc:close() '; } --- request GET /t --- response_body failed to prepend to dog: NOT_STORED dog not found --- no_error_log [error] === TEST 8: prepend to an exsistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) end local ok, err = memc:prepend("dog", 56) if not ok then ngx.say("failed to prepend to dog: ", err) end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) memc:close() '; } --- request GET /t --- response_body dog: 5632 --- no_error_log [error] === TEST 9: append to a nonexsistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:append("dog", 56) if not ok then ngx.say("failed to append to dog: ", err) end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) memc:close() '; } --- request GET /t --- response_body failed to append to dog: NOT_STORED dog not found --- no_error_log [error] === TEST 10: append to an exsistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) end local ok, err = memc:append("dog", 56) if not ok then ngx.say("failed to append to dog: ", err) end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) memc:close() '; } --- request GET /t --- response_body dog: 3256 --- no_error_log [error] === TEST 11: delete an exsistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) end local ok, err = memc:delete("dog") if not ok then ngx.say("failed to delete dog: ", err) end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) local res, flags, err = memc:add("dog", 772) if err then ngx.say("failed to add dog: ", err) return end memc:close() '; } --- request GET /t --- response_body dog not found --- no_error_log [error] === TEST 12: delete a nonexsistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:delete("dog") if not ok then ngx.say("failed to delete dog: ", err) end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) memc:close() '; } --- request GET /t --- response_body failed to delete dog: NOT_FOUND dog not found --- no_error_log [error] === TEST 13: delete an exsistent key with delay --- SKIP --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local ok, err = memc:delete("dog", 1) if not ok then ngx.say("failed to delete dog: ", err) end local ok, err = memc:add("dog", 76) if not ok then ngx.say("failed to add dog: ", err) end local ok, err = memc:replace("dog", 53) if not ok then ngx.say("failed to replace dog: ", err) end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res) memc:close() '; } --- request GET /t --- response_body failed to add dog: NOT_STORED failed to replace dog: NOT_STORED dog not found --- no_error_log [error] === TEST 14: flags --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32, 0, 526) if not ok then ngx.say("failed to set dog: ", err) return end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ")") memc:close() '; } --- request GET /t --- response_body dog: 32 (flags: 526) --- no_error_log [error] === TEST 15: set with exptime --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end ngx.location.capture("/sleep"); local ok, err = memc:set("dog", 32, 1, 526) if not ok then ngx.say("failed to set dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ")") memc:close() '; } location /sleep { echo_sleep 1.1; } --- request GET /t --- response_body dog not found --- no_error_log [error] === TEST 16: flush with a delay --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local ok, err = memc:flush_all(3) if not ok then ngx.say("failed to flush all: ", err) return end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ")") memc:close() '; } --- request GET /t --- response_body dog: 32 (flags: 0) --- no_error_log [error] === TEST 17: incr an existent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local value, err = memc:incr("dog", 2) if not value then ngx.say("failed to incr dog: ", err) return end ngx.say("dog is now: ", value) local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ")") memc:close() '; } --- request GET /t --- response_body dog is now: 34 dog: 34 (flags: 0) --- no_error_log [error] === TEST 18: incr a nonexistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local value, err = memc:incr("dog", 2) if not value then ngx.say("failed to incr dog: ", err) return end ngx.say("dog is now: ", value) local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ")") memc:close() '; } --- request GET /t --- response_body failed to incr dog: NOT_FOUND --- no_error_log [error] === TEST 19: decr an existent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local value, err = memc:decr("dog", 3) if not value then ngx.say("failed to decr dog: ", err) return end ngx.say("dog is now: ", value) local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ")") memc:close() '; } --- request GET /t --- response_body dog is now: 29 dog: 29 (flags: 0) --- no_error_log [error] === TEST 20: decr a nonexistent key --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local value, err = memc:decr("dog", 2) if not value then ngx.say("failed to decr dog: ", err) return end ngx.say("dog is now: ", value) local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ")") memc:close() '; } --- request GET /t --- response_body failed to decr dog: NOT_FOUND --- no_error_log [error] === TEST 21: general stats --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local lines, err = memc:stats() if not lines then ngx.say("failed to stats: ", err) return end ngx.say("stats:\\n", table.concat(lines, "\\n")) memc:close() '; } --- request GET /t --- response_body_like chop ^stats: STAT pid \d+ (?:STAT [^\n]+\n)*$ --- no_error_log [error] === TEST 22: stats items --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local lines, err = memc:stats("items") if not lines then ngx.say("failed to stats items: ", err) return end ngx.say("stats:\\n", table.concat(lines, "\\n")) memc:close() '; } --- request GET /t --- response_body_like chop ^stats: (?:STAT items:[^\n]+\n)*$ --- no_error_log [error] === TEST 23: stats sizes --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local lines, err = memc:stats("sizes") if not lines then ngx.say("failed to stats sizes: ", err) return end ngx.say("stats:\\n", table.concat(lines, "\\n")) memc:close() '; } --- request GET /t --- response_body_like chop ^stats: (?:STAT \d+ \d+\n)*$ --- no_error_log [error] === TEST 24: version --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ver, err = memc:version() if not ver then ngx.say("failed to get version: ", err) return end ngx.say("version: ", ver) memc:close() '; } --- request GET /t --- response_body_like chop ^version: \d+(?:\.\d+)*$ --- no_error_log [error] === TEST 25: quit --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:quit() if not ok then ngx.say("failed to quit: ", err) return end local ver, err = memc:version() if not ver then ngx.say("failed to get version: ", err) return end local ok, err = memc:close() if not ok then ngx.say("failed to close: ", err) return end ngx.say("closed successfully") '; } --- request GET /t --- response_body_like chop ^failed to get version: (closed|timeout|broken pipe|connection reset by peer)$ === TEST 26: verbosity --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:verbosity(2) if not ok then ngx.say("failed to quit: ", err) return end ngx.say("successfully set verbosity to level 2") local ver, err = memc:version() if not ver then ngx.say("failed to get version: ", err) return end local ok, err = memc:close() if not ok then ngx.say("failed to close: ", err) return end '; } --- request GET /t --- response_body successfully set verbosity to level 2 --- no_error_log [error] === TEST 27: multi get --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local ok, err = memc:set("cat", "hello\\nworld\\n") if not ok then ngx.say("failed to set dog: ", err) return end for i = 1, 2 do local results, err = memc:get({"dog", "blah", "cat"}) if err then ngx.say("failed to get keys: ", err) return end if not results then ngx.say("results empty") return end ngx.say("dog: ", results.dog and table.concat(results.dog, " ") or "not found") ngx.say("cat: ", results.cat and table.concat(results.cat, " ") or "not found") ngx.say("blah: ", results.blah and table.concat(results.blah, " ") or "not found") end local ok, err = memc:close() if not ok then ngx.say("failed to close: ", err) return end '; } --- request GET /t --- response_body dog: 32 0 cat: hello world 0 blah: not found dog: 32 0 cat: hello world 0 blah: not found --- no_error_log [error] === TEST 28: multi get (special chars in keys) --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog A", 32) if not ok then ngx.say("failed to set dog: ", err) return end local ok, err = memc:set("cat B", "hello\\nworld\\n") if not ok then ngx.say("failed to set dog: ", err) return end local results, err = memc:get({"dog A", "blah", "cat B"}) if err then ngx.say("failed to get dog: ", err) return end if not results then ngx.say("results empty") return end ngx.say("dog A: ", results["dog A"] and table.concat(results["dog A"], " ") or "not found") ngx.say("cat B: ", results["cat B"] and table.concat(results["cat B"], " ") or "not found") ngx.say("blah: ", results.blah and table.concat(results.blah, " ") or "not found") local ok, err = memc:close() if not ok then ngx.say("failed to close: ", err) return end '; } --- request GET /t --- response_body dog A: 32 0 cat B: hello world 0 blah: not found --- no_error_log [error] === TEST 29: connect timeout --- http_config eval: $::HttpConfig --- config resolver $TEST_NGINX_RESOLVER; location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(100) -- 100 ms local ok, err = memc:connect("www.taobao.com", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ")") memc:close() '; } --- request GET /t --- response_body failed to connect: timeout --- error_log lua tcp socket connect timed out === TEST 30: set keepalive and get reused times --- http_config eval: $::HttpConfig --- config resolver $TEST_NGINX_RESOLVER; location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local times = memc:get_reused_times() ngx.say("reused times: ", times) local ok, err = memc:set_keepalive() if not ok then ngx.say("failed to set keepalive: ", err) return end ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end times = memc:get_reused_times() ngx.say("reused times: ", times) '; } --- request GET /t --- response_body reused times: 0 reused times: 1 --- no_error_log [error] === TEST 31: gets (single key, found) --- http_config eval: $::HttpConfig --- config resolver $TEST_NGINX_RESOLVER; location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local res, flags, cas_uniq, err = memc:gets("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ", cas_uniq: ", cas_uniq, ")") '; } --- request GET /t --- response_body_like chop ^dog: 32 \(flags: 0, cas_uniq: \d+\)$ --- no_error_log [error] === TEST 32: gets (single key, not found) --- http_config eval: $::HttpConfig --- config resolver $TEST_NGINX_RESOLVER; location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local res, flags, cas_uniq, err = memc:gets("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ", cas_uniq: ", cas_uniq, ")") '; } --- request GET /t --- response_body_like chop dog not found --- no_error_log [error] === TEST 33: gets (multiple key) --- http_config eval: $::HttpConfig --- config resolver $TEST_NGINX_RESOLVER; location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local ok, err = memc:set("cat", "hello\\nworld\\n") if not ok then ngx.say("failed to set dog: ", err) return end local results, err = memc:gets({"dog", "blah", "cat"}) if err then ngx.say("failed to get keys: ", err) return end if not results then ngx.say("results empty") return end if results.dog then ngx.say("dog: ", table.concat(results.dog, " ")) else ngx.say("dog not found") end if results.blah then ngx.say("blah: ", table.concat(results.blah, " ")) else ngx.say("blah not found") end if results.cat then ngx.say("cat: ", table.concat(results.cat, " ")) else ngx.say("cat not found") end local ok, err = memc:close() if not ok then ngx.say("failed to close: ", err) return end '; } --- request GET /t --- response_body_like chop ^dog: 32 0 \d+ blah not found cat: hello world 0 \d+$ --- no_error_log [error] === TEST 34: gets (single key) + cas --- http_config eval: $::HttpConfig --- config resolver $TEST_NGINX_RESOLVER; location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local value, flags, cas_uniq, err = memc:gets("dog") if err then ngx.say("failed to get dog: ", err) return end ngx.say("dog: ", value, " (flags: ", flags, ", cas_uniq: ", cas_uniq, ")") local ok, err = memc:cas("dog", "hello world", cas_uniq, 0, 78) if not ok then ngx.say("failed to cas: ", err) return end ngx.say("cas succeeded") local value, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end ngx.say("dog: ", value, " (flags: ", flags, ")") '; } --- request GET /t --- response_body_like chop ^dog: 32 \(flags: 0, cas_uniq: \d+\) cas succeeded dog: hello world \(flags: 78\)$ --- no_error_log [error] === TEST 35: gets (multi key) + cas --- http_config eval: $::HttpConfig --- config resolver $TEST_NGINX_RESOLVER; location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local results, err = memc:gets({"dog"}) if err then ngx.say("failed to get dog: ", err) return end local value, flags, cas_uniq, err = unpack(results.dog) ngx.say("dog: ", value, " (flags: ", flags, ", cas_uniq: ", cas_uniq, ")") local ok, err = memc:cas("dog", "hello world", cas_uniq, 0, 78) if not ok then ngx.say("failed to cas: ", err) return end ngx.say("cas succeeded") local value, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end ngx.say("dog: ", value, " (flags: ", flags, ")") '; } --- request GET /t --- response_body_like chop ^dog: 32 \(flags: 0, cas_uniq: \d+\) cas succeeded dog: hello world \(flags: 78\)$ --- no_error_log [error] === TEST 36: gets (single key) + cas --- http_config eval: $::HttpConfig --- config resolver $TEST_NGINX_RESOLVER; location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", 32) if not ok then ngx.say("failed to set dog: ", err) return end local value, flags, cas_uniq, err = memc:gets("dog") if err then ngx.say("failed to get dog: ", err) return end ok, err = memc:set("dog", 117) if not ok then ngx.say("failed to set dog: ", err) return end ngx.say("dog: ", value, " (flags: ", flags, ", cas_uniq: ", cas_uniq, ")") local ok, err = memc:cas("dog", "hello world", cas_uniq, 0, 78) if not ok then ngx.say("failed to cas: ", err) return end ngx.say("cas succeeded") local value, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end ngx.say("dog: ", value, " (flags: ", flags, ")") '; } --- request GET /t --- response_body_like chop ^dog: 32 \(flags: 0, cas_uniq: \d+\) failed to cas: EXISTS$ --- no_error_log [error] === TEST 37: change escape method --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' function identity(str) return str end local memcached = require "resty.memcached" local memc = memcached:new{ key_transform = { identity, identity }} local key = "dog&cat" memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set(key, 32) if not ok then ngx.say("failed to set dog: ", err) return end for i = 1, 2 do local res, flags, err = memc:get(key) if err then ngx.say("failed to get", key, ": ", err) return end if not res then ngx.say(key, " not found") return end ngx.say(key, ": ", res, " (flags: ", flags, ")") end memc:close() '; } --- request GET /t --- response_body dog&cat: 32 (flags: 0) dog&cat: 32 (flags: 0) --- no_error_log [error] === TEST 38: gets (multiple key) + change only unescape key --- http_config eval: $::HttpConfig --- config resolver $TEST_NGINX_RESOLVER; location /t { content_by_lua ' function identity(str) return str end local memcached = require "resty.memcached" local memc = memcached:new{key_transform = {ngx.escape_uri, identity}} local key = "dog&cat" memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set(key, 32) if not ok then ngx.say("failed to set ", key, ": ", err) return end local ok, err = memc:set("cat", "hello\\nworld\\n") if not ok then ngx.say("failed to set dog: ", err) return end local results, err = memc:gets({key, "blah", "cat"}) if err then ngx.say("failed to get keys: ", err) return end if not results then ngx.say("results empty") return end if results[key] then ngx.say(key, ": ", table.concat(results[key], " ")) else ngx.say(key, " not found") end -- encode key for second run key = ngx.escape_uri(key) if results[key] then ngx.say(key, ": ", table.concat(results[key], " ")) else ngx.say(key, " not found") end if results.blah then ngx.say("blah: ", table.concat(results.blah, " ")) else ngx.say("blah not found") end if results.cat then ngx.say("cat: ", table.concat(results.cat, " ")) else ngx.say("cat not found") end local ok, err = memc:close() if not ok then ngx.say("failed to close: ", err) return end '; } --- request GET /t --- response_body_like chop ^dog&cat not found dog%26cat: 32 0 \d+ blah not found cat: hello world 0 \d+$ --- no_error_log [error] lua-resty-memcached-master/t/tableset.t000066400000000000000000000060451205405667600204530ustar00rootroot00000000000000# vim:set ft= ts=4 sw=4 et: use Test::Nginx::Socket; use Cwd qw(cwd); repeat_each(2); plan tests => repeat_each() * (3 * blocks()); my $pwd = cwd(); our $HttpConfig = qq{ lua_package_path "$pwd/lib/?.lua;;"; }; $ENV{TEST_NGINX_RESOLVER} = '8.8.8.8'; $ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211; no_long_string(); run_tests(); __DATA__ === TEST 1: set with table --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", { "c", "a", "t" }) if not ok then ngx.say("failed to set dog: ", err) return end for i = 1, 2 do local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ")") end memc:close() '; } --- request GET /t --- response_body dog: cat (flags: 0) dog: cat (flags: 0) --- no_error_log [error] === TEST 2: set with nested table --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memcached = require "resty.memcached" local memc = memcached:new() memc:set_timeout(1000) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then ngx.say("failed to connect: ", err) return end local ok, err = memc:flush_all() if not ok then ngx.say("failed to flush all: ", err) return end local ok, err = memc:set("dog", { "c", "a", { "t"} }) if not ok then ngx.say("failed to set dog: ", err) return end for i = 1, 2 do local res, flags, err = memc:get("dog") if err then ngx.say("failed to get dog: ", err) return end if not res then ngx.say("dog not found") return end ngx.say("dog: ", res, " (flags: ", flags, ")") end memc:close() '; } --- request GET /t --- response_body dog: cat (flags: 0) dog: cat (flags: 0) --- no_error_log [error] lua-resty-memcached-master/t/version.t000066400000000000000000000011471205405667600203330ustar00rootroot00000000000000# vim:set ft= ts=4 sw=4 et: use Test::Nginx::Socket; use Cwd qw(cwd); repeat_each(2); plan tests => repeat_each() * (3 * blocks()); my $pwd = cwd(); our $HttpConfig = qq{ lua_package_path "$pwd/lib/?.lua;;"; }; $ENV{TEST_NGINX_RESOLVER} = '8.8.8.8'; no_long_string(); #no_diff(); run_tests(); __DATA__ === TEST 1: basic --- http_config eval: $::HttpConfig --- config location /t { content_by_lua ' local memc = require "resty.memcached" ngx.say(memc._VERSION) '; } --- request GET /t --- response_body_like chop ^\d+\.\d+$ --- no_error_log [error] lua-resty-memcached-master/valgrind.suppress000066400000000000000000000232551205405667600216360ustar00rootroot00000000000000{ Memcheck:Cond fun:lj_str_new } { Memcheck:Param write(buf) fun:__write_nocancel fun:ngx_log_error_core fun:ngx_resolver_read_response } { Memcheck:Cond fun:ngx_sprintf_num fun:ngx_vslprintf fun:ngx_log_error_core fun:ngx_resolver_read_response fun:ngx_epoll_process_events fun:ngx_process_events_and_timers fun:ngx_single_process_cycle fun:main } { Memcheck:Addr1 fun:ngx_vslprintf fun:ngx_snprintf fun:ngx_sock_ntop fun:ngx_event_accept } { Memcheck:Param write(buf) fun:__write_nocancel fun:ngx_log_error_core fun:ngx_resolver_read_response fun:ngx_event_process_posted fun:ngx_process_events_and_timers fun:ngx_single_process_cycle fun:main } { Memcheck:Cond fun:ngx_sprintf_num fun:ngx_vslprintf fun:ngx_log_error_core fun:ngx_resolver_read_response fun:ngx_event_process_posted fun:ngx_process_events_and_timers fun:ngx_single_process_cycle fun:main } { exp-sgcheck:SorG fun:lj_str_new fun:lua_pushlstring } { Memcheck:Leak fun:malloc fun:ngx_alloc obj:* } { exp-sgcheck:SorG fun:lj_str_new fun:lua_pushlstring } { exp-sgcheck:SorG fun:ngx_http_lua_ndk_set_var_get } { exp-sgcheck:SorG fun:lj_str_new fun:lua_getfield } { exp-sgcheck:SorG fun:lj_str_new fun:lua_setfield } { exp-sgcheck:SorG fun:ngx_http_variables_init_vars fun:ngx_http_block } { exp-sgcheck:SorG fun:ngx_conf_parse } { exp-sgcheck:SorG fun:ngx_vslprintf fun:ngx_log_error_core } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_calloc fun:ngx_event_process_init } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_malloc fun:ngx_pcalloc } { Memcheck:Addr4 fun:lj_str_new fun:lua_setfield } { Memcheck:Addr4 fun:lj_str_new fun:lua_getfield } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:(below main) } { Memcheck:Param epoll_ctl(event) fun:epoll_ctl } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_event_process_init } { Memcheck:Cond fun:ngx_conf_flush_files fun:ngx_single_process_cycle } { Memcheck:Cond fun:memcpy fun:ngx_vslprintf fun:ngx_log_error_core fun:ngx_http_charset_header_filter } { Memcheck:Leak fun:memalign fun:posix_memalign fun:ngx_memalign fun:ngx_pcalloc } { Memcheck:Addr4 fun:lj_str_new fun:lua_pushlstring } { Memcheck:Cond fun:lj_str_new fun:lj_str_fromnum } { Memcheck:Cond fun:lj_str_new fun:lua_pushlstring } { Memcheck:Addr4 fun:lj_str_new fun:lua_setfield fun:ngx_http_lua_cache_store_code } { Memcheck:Cond fun:lj_str_new fun:lua_getfield fun:ngx_http_lua_cache_load_code } { Memcheck:Cond fun:lj_str_new fun:lua_setfield fun:ngx_http_lua_cache_store_code } { Memcheck:Addr4 fun:lj_str_new fun:lua_getfield fun:ngx_http_lua_cache_load_code } { Memcheck:Param socketcall.setsockopt(optval) fun:setsockopt fun:drizzle_state_connect } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_pool_cleanup_add } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_pnalloc } { Memcheck:Cond fun:ngx_conf_flush_files fun:ngx_single_process_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_pcalloc } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_malloc fun:ngx_palloc_large } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_create_pool } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_malloc fun:ngx_palloc } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_malloc fun:ngx_pnalloc } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_array_push fun:ngx_http_get_variable_index fun:ngx_http_memc_add_variable fun:ngx_http_memc_init fun:ngx_http_block fun:ngx_conf_parse fun:ngx_init_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_event_process_init fun:ngx_single_process_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_crc32_table_init fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_event_process_init fun:ngx_worker_process_init fun:ngx_worker_process_cycle fun:ngx_spawn_process fun:ngx_start_worker_processes fun:ngx_master_process_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_pcalloc fun:ngx_hash_init fun:ngx_http_variables_init_vars fun:ngx_http_block fun:ngx_conf_parse fun:ngx_init_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_pcalloc fun:ngx_http_upstream_drizzle_create_srv_conf fun:ngx_http_upstream fun:ngx_conf_parse fun:ngx_http_block fun:ngx_conf_parse fun:ngx_init_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_pcalloc fun:ngx_hash_keys_array_init fun:ngx_http_variables_add_core_vars fun:ngx_http_core_preconfiguration fun:ngx_http_block fun:ngx_conf_parse fun:ngx_init_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_array_push fun:ngx_hash_add_key fun:ngx_http_add_variable fun:ngx_http_echo_add_variables fun:ngx_http_echo_handler_init fun:ngx_http_block fun:ngx_conf_parse fun:ngx_init_cycle } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_pcalloc fun:ngx_http_upstream_drizzle_create_srv_conf fun:ngx_http_core_server fun:ngx_conf_parse fun:ngx_http_block fun:ngx_conf_parse fun:ngx_init_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_pcalloc fun:ngx_http_upstream_drizzle_create_srv_conf fun:ngx_http_block fun:ngx_conf_parse fun:ngx_init_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_array_push fun:ngx_hash_add_key fun:ngx_http_variables_add_core_vars fun:ngx_http_core_preconfiguration fun:ngx_http_block fun:ngx_conf_parse fun:ngx_init_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_pcalloc fun:ngx_init_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_hash_init fun:ngx_http_upstream_init_main_conf fun:ngx_http_block fun:ngx_conf_parse fun:ngx_init_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_pcalloc fun:ngx_http_drizzle_keepalive_init fun:ngx_http_upstream_drizzle_init fun:ngx_http_upstream_init_main_conf fun:ngx_http_block fun:ngx_conf_parse fun:ngx_init_cycle fun:main } { Memcheck:Leak fun:malloc fun:ngx_alloc fun:ngx_palloc_large fun:ngx_palloc fun:ngx_hash_init fun:ngx_http_variables_init_vars fun:ngx_http_block fun:ngx_conf_parse fun:ngx_init_cycle fun:main } { Memcheck:Leak fun:memalign fun:posix_memalign fun:ngx_memalign fun:ngx_create_pool } { Memcheck:Leak fun:memalign fun:posix_memalign fun:ngx_memalign fun:ngx_palloc_block fun:ngx_palloc }