From 52832266a4815b915291253c9997cf1b825a5a11 Mon Sep 17 00:00:00 2001 From: smallfish Date: Wed, 31 Oct 2012 13:50:26 +0800 Subject: [PATCH] support tcp keepalive --- README.md | 9 +++++++-- lib/resty/beanstalkd.lua | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f112c6..76b5b6d 100644 --- a/README.md +++ b/README.md @@ -78,8 +78,13 @@ Synopsis end end - -- close - bean:close() + -- put it into the connection pool of size 100, + -- with 0 idle timeout + + bean:set_keepalive(0, 100) + + -- close and quit beanstalkd + -- bean:close() '; } } diff --git a/lib/resty/beanstalkd.lua b/lib/resty/beanstalkd.lua index 236f97a..ef54e70 100644 --- a/lib/resty/beanstalkd.lua +++ b/lib/resty/beanstalkd.lua @@ -29,6 +29,14 @@ function set_timeout(self, timeout) return sock:settimeout(timeout) end +function set_keepalive(self, ...) + local sock = self.sock + if not sock then + return nil, "not initialized" + end + return sock:setkeepalive(...) +end + function connect(self, host, port, ...) local sock = self.sock if not sock then