From ce28d2409b20e06e33dc5a33605786e7d2b2594f Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Thu, 28 Aug 2014 12:13:37 -0700 Subject: [PATCH] feature: set_timeout() now returns the result of the operation. thanks Guanlan Dai for the report. --- README.markdown | 4 +++- lib/resty/memcached.lua | 3 ++- t/sanity.t | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index 19f217d..6fd6622 100644 --- a/README.markdown +++ b/README.markdown @@ -201,10 +201,12 @@ The `flags` parameter is optional, defaults to `0`. set_timeout ---------- -`syntax: memc:set_timeout(time)` +`syntax: ok, err = memc:set_timeout(time)` Sets the timeout (in ms) protection for subsequent operations, including the `connect` method. +Returns 1 when successful and nil plus a string describing the error otherwise. + [Back to TOC](#table-of-contents) set_keepalive diff --git a/lib/resty/memcached.lua b/lib/resty/memcached.lua index d8ffb3b..79f9782 100644 --- a/lib/resty/memcached.lua +++ b/lib/resty/memcached.lua @@ -56,7 +56,8 @@ function _M.set_timeout(self, timeout) return nil, "not initialized" end - return sock:settimeout(timeout) + sock:settimeout(timeout) + return 1 end diff --git a/t/sanity.t b/t/sanity.t index 1a10660..2661e13 100644 --- a/t/sanity.t +++ b/t/sanity.t @@ -30,7 +30,7 @@ __DATA__ local memcached = require "resty.memcached" local memc = memcached:new() - memc:set_timeout(1000) -- 1 sec + assert(memc:set_timeout(1000)) -- 1 sec local ok, err = memc:connect("127.0.0.1", $TEST_NGINX_MEMCACHED_PORT) if not ok then