Hi! Have you try to use pool and keepalive?
суббота, 22 июня 2019 г., 14:57:28 UTC+3 пользователь Hadi Abbasi написал:
> Hey Friends...
>
> as I followed many tutorials and documents, in openresty, for sending data via socket and rabbitmq ,... or sending data to redis or .... we have to make new connector object then connect and send our data, then we have to close it!
> but when our sending rate is too much, connection and handshaking can be time and process consuming, so I'm looking for a way to make one shared connector object which was connected and send data for multiple times!
> so I think I can use a way like this (redis example):
>
>
> local redisLib = require "resty.redis"
> ngx.shared.redis = redisLib:new()
> ngx.shared.redis:set_timeout(config.socket_timeout)
> local okRedis, errRedisCon = ngx.shared.redis:connect(Ip,Port)
> if not okRedis then
> ngx.log(ngx.DEBUG,"redis connection error:" .. errRedisCon)
> end
> ngx.shared.redis:select(Db_no)
>
>
> when I wanna send data:
>
>
>
> ngx.shared.redis:set(Key,Value)
> it can be used for socket connection or rabbitmq or ...
> is it suggested way or there is better way to do that?
> it was better to have an error event to reconnecting suing time_out!
> thanks a lot...
> Best Regards,
> Hadi
Attachment:
D5611C4A-8D1F-4DD1-AA8F-3C1EBB6A2416.jpeg
Description: JPEG image