You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/10/13 15:13:12 UTC

[GitHub] [apisix] siaron opened a new issue #5223: request help: limit-count-redis.lua 中redis的连接

siaron opened a new issue #5223:
URL: https://github.com/apache/apisix/issues/5223


   ### Issue description
   
   ```
      local red = redis_new()
       local timeout = conf.redis_timeout or 1000    -- 1sec
       core.log.info("ttl key: ", key, " timeout: ", timeout)
   
       red:set_timeouts(timeout, timeout, timeout)
   
       local ok, err = red:connect(conf.redis_host, conf.redis_port or 6379)
       if not ok then
           return false, err
       end
   
       local count
       count, err = red:get_reused_times()
       if 0 == count then
           if conf.redis_password and conf.redis_password ~= '' then
               local ok, err = red:auth(conf.redis_password)
               if not ok then
                   return nil, err
               end
           end
   
           -- select db
           if conf.redis_database ~= 0 then
               local ok, err = red:select(conf.redis_database)
               if not ok then
                   return false, "failed to change redis db, err: " .. err
               end
           end
       elseif err then
           -- core.log.info(" err: ", err)
           return nil, err
       end
   ```
   每次都会重新创建一个redis 的connection吗? 还是
   ```
       local ok, err = red:connect(conf.redis_host, conf.redis_port or 6379)
   ```
   这一步后面后连接池?
   
   ### Environment
   
   - apisix version (cmd: `apisix version`):
   - OS (cmd: `uname -a`):
   - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`):
   - etcd version, if have (cmd: run `curl http://127.0.0.1:9090/v1/server_info` to get the info from server-info API):
   - apisix-dashboard version, if have:
   - the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner):
   - luarocks version, if the issue is about installation (cmd: `luarocks --version`):
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] siaron commented on issue #5223: request help: limit-count-redis.lua 中redis的连接

Posted by GitBox <gi...@apache.org>.
siaron commented on issue #5223:
URL: https://github.com/apache/apisix/issues/5223#issuecomment-942896502


   @tokers 在自定义的负载均衡插件中如何获取客户端ip, 我打印ctx为
   ```
   {
     "conf_id": "376794584073634862",
     "balancer_try_count": 1,
     "var": {
       "_request": "cdata<void *>: 0x7fb862020850",
       "_cache": {
         "upstream_scheme": "http",
         "host": "127.0.0.1",
         "uri": "/uaa/test/hello",
         "remote_addr": "127.0.0.1",
         "request_method": "GET"
       }
     },
     "route_id": "376794584073634862",
     "route_name": "uaa",
     "plugins": {},
     "matched_upstream": {
       "type": "original_destination",
       "keepalive_pool": "table: 0x0a176800",
       "create_time": 1634116608,
       "discovery_type": "nacos",
       "name": "uaa",
       "id": "376794475088839726",
       "timeout": "table: 0x13c7bf98",
       "update_time": 1634178548,
       "desc": "uaa服务",
       "hash_on": "vars",
       "pass_host": "pass",
       "scheme": "http",
       "service_name": "uaa-service",
       "parent": "table: 0x13c761a8",
       "key": "{\"redis_host\":\"127.0.0.1\",\"redis_port\":6379,\"redis_password\":\"redis\",\"redis_database\":0,\"redis_timeout\":1001,\"http_header\":\"server_host\",\"client_ip_header\":\"remote_addr\"}",
       "nodes": "table: 0x1887a580"
     },
     "curr_req_matched": {
       "_path": "/uaa/*",
       ":ext": "test/hello",
       "_method": "GET"
     },
     "upstream_scheme": "http",
     "upstream_healthcheck_parent": {
       "modifiedIndex": 1827,
       "key": "/apisix/upstreams/376794475088839726",
       "createdIndex": 1378,
       "clean_handlers": {},
       "value": {
         "create_time": 1634116608,
         "hash_on": "vars",
         "scheme": "http",
         "key": "{\"redis_host\":\"127.0.0.1\",\"redis_port\":6379,\"redis_password\":\"redis\",\"redis_database\":0,\"redis_timeout\":1001,\"http_header\":\"server_host\",\"client_ip_header\":\"remote_addr\"}",
         "discovery_type": "nacos",
         "type": "original_destination",
         "keepalive_pool": {
           "requests": 1000,
           "size": 320,
           "idle_timeout": 60
         },
         "name": "uaa",
         "nodes": "table: 0x1863bdc0",
         "desc": "uaa服务",
         "service_name": "uaa-service",
         "id": "376794475088839726",
         "nodes_ref": [
           {
             "host": "192.168.27.173",
             "port": 30101,
             "weight": 1,
             "priority": 0
           },
           {
             "host": "192.168.27.173",
             "port": 20101,
             "weight": 1,
             "priority": 0
           }
         ],
         "timeout": {
           "send": 6,
           "connect": 6,
           "read": 6
         },
         "update_time": 1634178548,
         "parent": "table: 0x13c761a8",
         "pass_host": "pass",
         "original_nodes": [
           {
             "port": 30101,
             "weight": 1,
             "host": "192.168.27.173"
           },
           {
             "port": 20101,
             "weight": 1,
             "host": "192.168.27.173"
           }
         ]
       },
       "has_domain": false
     },
     "upstream_version": 1380,
     "upstream_key": "original_destination#upstream_table: 0x18630ae0",
     "upstream_conf": "table: 0x18630ae0",
     "conf_type": "route",
     "matched_route": {
       "modifiedIndex": 1380,
       "update_count": 0,
       "key": "/apisix/routes/376794584073634862",
       "createdIndex": 1380,
       "value": {
         "name": "uaa",
         "methods": [
           "GET",
           "POST",
           "PUT",
           "DELETE",
           "PATCH",
           "HEAD",
           "OPTIONS",
           "CONNECT",
           "TRACE"
         ],
         "update_time": 1634116673,
         "upstream_id": "376794475088839726",
         "priority": 0,
         "uri": "/uaa/*",
         "status": 1,
         "id": "376794584073634862",
         "create_time": 1634116673
       },
       "clean_handlers": {},
       "has_domain": false,
       "orig_modifiedIndex": 1380
     },
     "conf_version": 1380
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] siaron closed issue #5223: request help: limit-count-redis.lua 中redis的连接

Posted by GitBox <gi...@apache.org>.
siaron closed issue #5223:
URL: https://github.com/apache/apisix/issues/5223


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] shuaijinchao edited a comment on issue #5223: request help: limit-count-redis.lua 中redis的连接

Posted by GitBox <gi...@apache.org>.
shuaijinchao edited a comment on issue #5223:
URL: https://github.com/apache/apisix/issues/5223#issuecomment-942876200


   The current Redis connection will be put into the ngx_lua cosocket connection pool here, and it will be looked up in the connection pool first when connecting next time.
   
   https://github.com/apache/apisix/blob/a7c040f117ef9d21e88ebe2d01b04a03d008a115/apisix/plugins/limit-count/limit-count-redis.lua#L100
   
   ---
   
   refer to:
   
   https://github.com/openresty/lua-resty-redis#connect
   https://github.com/openresty/lua-resty-redis#set_keepalive
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] shuaijinchao edited a comment on issue #5223: request help: limit-count-redis.lua 中redis的连接

Posted by GitBox <gi...@apache.org>.
shuaijinchao edited a comment on issue #5223:
URL: https://github.com/apache/apisix/issues/5223#issuecomment-942876200


   Will create a connection pool


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] shuaijinchao commented on issue #5223: request help: limit-count-redis.lua 中redis的连接

Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on issue #5223:
URL: https://github.com/apache/apisix/issues/5223#issuecomment-942876200


   It is not recommended to expose APISIX nodes to the public network because there is a potential risk of being attacked. According to past experience, in the actual production environment, the upper layer of APISIX nodes must have 4-layer load balancing products to ensure the distribution of traffic, the detection of the health status of APISIX nodes, and the high availability of APISIX clusters.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] siaron edited a comment on issue #5223: request help: limit-count-redis.lua 中redis的连接

Posted by GitBox <gi...@apache.org>.
siaron edited a comment on issue #5223:
URL: https://github.com/apache/apisix/issues/5223#issuecomment-942896502


   @tokers 在自定义的负载均衡插件中如何获取客户端ip, 我打印ctx为
   ```
   {
     "conf_id": "376794584073634862",
     "balancer_try_count": 1,
     "var": {
       "_request": "cdata<void *>: 0x7fb862020850",
       "_cache": {
         "upstream_scheme": "http",
         "host": "127.0.0.1",
         "uri": "/uaa/test/hello",
         "remote_addr": "127.0.0.1",
         "request_method": "GET"
       }
     },
     "route_id": "376794584073634862",
     "route_name": "uaa",
     "plugins": {},
     "matched_upstream": {
       "type": "original_destination",
       "keepalive_pool": "table: 0x0a176800",
       "create_time": 1634116608,
       "discovery_type": "nacos",
       "name": "uaa",
       "id": "376794475088839726",
       "timeout": "table: 0x13c7bf98",
       "update_time": 1634178548,
       "desc": "uaa服务",
       "hash_on": "vars",
       "pass_host": "pass",
       "scheme": "http",
       "service_name": "uaa-service",
       "parent": "table: 0x13c761a8",
       "key": "{\"redis_host\":\"127.0.0.1\",\"redis_port\":6379,\"redis_password\":\"redis\",\"redis_database\":0,\"redis_timeout\":1001,\"http_header\":\"server_host\",\"client_ip_header\":\"remote_addr\"}",
       "nodes": "table: 0x1887a580"
     },
     "curr_req_matched": {
       "_path": "/uaa/*",
       ":ext": "test/hello",
       "_method": "GET"
     },
     "upstream_scheme": "http",
     "upstream_healthcheck_parent": {
       "modifiedIndex": 1827,
       "key": "/apisix/upstreams/376794475088839726",
       "createdIndex": 1378,
       "clean_handlers": {},
       "value": {
         "create_time": 1634116608,
         "hash_on": "vars",
         "scheme": "http",
         "key": "{\"redis_host\":\"127.0.0.1\",\"redis_port\":6379,\"redis_password\":\"redis\",\"redis_database\":0,\"redis_timeout\":1001,\"http_header\":\"server_host\",\"client_ip_header\":\"remote_addr\"}",
         "discovery_type": "nacos",
         "type": "original_destination",
         "keepalive_pool": {
           "requests": 1000,
           "size": 320,
           "idle_timeout": 60
         },
         "name": "uaa",
         "nodes": "table: 0x1863bdc0",
         "desc": "uaa服务",
         "service_name": "uaa-service",
         "id": "376794475088839726",
         "nodes_ref": [
           {
             "host": "192.168.27.173",
             "port": 30101,
             "weight": 1,
             "priority": 0
           },
           {
             "host": "192.168.27.173",
             "port": 20101,
             "weight": 1,
             "priority": 0
           }
         ],
         "timeout": {
           "send": 6,
           "connect": 6,
           "read": 6
         },
         "update_time": 1634178548,
         "parent": "table: 0x13c761a8",
         "pass_host": "pass",
         "original_nodes": [
           {
             "port": 30101,
             "weight": 1,
             "host": "192.168.27.173"
           },
           {
             "port": 20101,
             "weight": 1,
             "host": "192.168.27.173"
           }
         ]
       },
       "has_domain": false
     },
     "upstream_version": 1380,
     "upstream_key": "original_destination#upstream_table: 0x18630ae0",
     "upstream_conf": "table: 0x18630ae0",
     "conf_type": "route",
     "matched_route": {
       "modifiedIndex": 1380,
       "update_count": 0,
       "key": "/apisix/routes/376794584073634862",
       "createdIndex": 1380,
       "value": {
         "name": "uaa",
         "methods": [
           "GET",
           "POST",
           "PUT",
           "DELETE",
           "PATCH",
           "HEAD",
           "OPTIONS",
           "CONNECT",
           "TRACE"
         ],
         "update_time": 1634116673,
         "upstream_id": "376794475088839726",
         "priority": 0,
         "uri": "/uaa/*",
         "status": 1,
         "id": "376794584073634862",
         "create_time": 1634116673
       },
       "clean_handlers": {},
       "has_domain": false,
       "orig_modifiedIndex": 1380
     },
     "conf_version": 1380
   }
   ```
   ctx.var["http_" .. "X_Real_ip"] 可以 吗? 但是我获取到的是空的.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tokers commented on issue #5223: request help: limit-count-redis.lua 中redis的连接

Posted by GitBox <gi...@apache.org>.
tokers commented on issue #5223:
URL: https://github.com/apache/apisix/issues/5223#issuecomment-942857744


   @siaron Yes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] siaron commented on issue #5223: request help: limit-count-redis.lua 中redis的连接

Posted by GitBox <gi...@apache.org>.
siaron commented on issue #5223:
URL: https://github.com/apache/apisix/issues/5223#issuecomment-942897092


   > The current Redis connection will be put into the ngx_lua cosocket connection pool here, and it will be looked up in the connection pool first when connecting next time.
   > 
   > https://github.com/apache/apisix/blob/a7c040f117ef9d21e88ebe2d01b04a03d008a115/apisix/plugins/limit-count/limit-count-redis.lua#L100
   > 
   > refer to:
   > 
   > https://github.com/openresty/lua-resty-redis#connect https://github.com/openresty/lua-resty-redis#set_keepalive
   
   ok I get it , thanks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org