Comments (4)
@leeguevara Thank you for the report but I have several comments for you first:
-
I cannot reproduce this issue on my side. Please provide a minimal and still complete example that I can run locally. I have no idea how your
InitializeRedis
andKeepAliveRedis
are actually defined. -
You should do proper error handling for the
blpop
call in your Lua code, that is, do something like this:local msg, err = redis_handle:blpop("list1", "0"); if not msg then ngx.log(ngx.ERR, "blpop failed: ", err) return ngx.exit(500) end
-
The ngx_lua cosocket read operations have a different timeout guard of 60 seconds: https://github.com/chaoslawful/lua-nginx-module#lua_socket_read_timeout You need to adjust this by configuring this directive or call the
set_timeout
method of yourresty.redis
objects.
from lua-resty-redis.
Thank you.
The original test code as follow:
the conf file:
#user nobody;
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
#pid logs/nginx.pid;
events {
worker_connections 3072;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 75s;
#gzip on;
server {
listen 80 backlog=1024;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /TestRedis {
content_by_lua_file 'lua/AppStore/Test_Redis.lua';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Test_Redis.lua
cjson=require "cjson";
redis=require "resty.redis";
function InitializeRedis(host, port, timeout)
local handle=redis:new();
if timeout
then
handle:set_timeout(timeout);
end
if handle
then
local ok, err=handle:connect(host, port);
end
return handle, err;
end
function KeepAliveRedis(db_handle, timeout)
if timeout==nil
then
db_handle:set_keepalive(10000, 100);
else
db_handle:set_keepalive(timeout, 100);
end
end
function Testblpop()
local count=1;
local msg=nil;
local err='';
local redis_handle, err=InitializeRedis(redis_host, redis_port);
while true
do
ngx.log(ngx.NOTICE, string.format("count: %d", count));
msg, err=redis_handle:blpop("list1", '0');
ngx.log(ngx.NOTICE, string.format("msg: %s", cjson.encode(msg)));
count=count+1;
ngx.sleep(1);
end
KeepAliveRedis(redis_handle);
end
Testblpop();
I access Testblpop using curl
curl "http://localhost/TestRedis"
Thanks a lot ^_^
from lua-resty-redis.
Sorry. It's not a problem. It's my fault.
The "blpop" blocks my connect. After a while, the redis connection will be timeout. Then an error will occur, the "blpop" function return. So it seems that the "blpop" function couldn't block the programme.
I also have a question.
"how to make the redis connection never be timeout?"
I have tried the "set_timeout" function.
Thanks a lot.
from lua-resty-redis.
Hello!
On Tue, Dec 31, 2013 at 2:54 AM, leeguevara [email protected] wrote:
I also have a question.
"how to make the redis connection never be timeout?"
I have tried the "set_timeout" function.
Well, you can just use a very large timeout value, like 1576800000000
for 50 years :)
-agentzh
from lua-resty-redis.
Related Issues (20)
- redis:connect is taking exactly 60 seconds for connection
- SSL not working
- The performance of redis pipeline mode is unstable HOT 3
- CLIENT SETNAME?
- redis:get(key) question HOT 2
- opm package outdated HOT 1
- Connection pool not creating HOT 2
- How to create a single redis connection HOT 5
- this support two-way authentication?
- Add keepalive for redis client to make the connections reliable
- Nginx 1.24 HOT 2
- Nginx creates more connection than poolsize, backlog to redis HOT 5
- lua tcp socket read timed out, context: ssl_certificate_by_lua*, client: 172.69.58.204, server: 0.0.0.0:443 HOT 2
- redis set_keepalive doesn't work HOT 1
- lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/redis.lua:357: bad request HOT 1
- no request found HOT 1
- Add the host:port to the error message
- Reading from client: error:0A000126:SSL routines::unexpected eof while reading
- red:smembers("key"), sometime not include the new member? HOT 6
- [Feature Request] Pipeline coroutine safety HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua-resty-redis.