Giter Club home page Giter Club logo

Comments (4)

agentzh avatar agentzh commented on July 29, 2024

@leeguevara Thank you for the report but I have several comments for you first:

  1. 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 and KeepAliveRedis are actually defined.

  2. 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
    
  3. 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 your resty.redis objects.

from lua-resty-redis.

leeguevara avatar leeguevara commented on July 29, 2024

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.

leeguevara avatar leeguevara commented on July 29, 2024

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.

agentzh avatar agentzh commented on July 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.