lua-resty-redis icon indicating copy to clipboard operation
lua-resty-redis copied to clipboard

will read_reply() lost message in Pub/Sub?

Open zjjott opened this issue 8 years ago • 4 comments
trafficstars

I have write a Pub/Sub code in worker_init and work very well,thanks agentzh abundant issue support ,code under here:

local res, err = red:subscribe("nginx")
    while not ngx.worker.exiting() do
        repeat
            local key, err = red:read_reply()
            if not key then--here timeout
                ngx.log(ngx.INFO,"err is :",err)
                break
            end
            key = key[3]
            local value,err = red2:get(key)
            if value == nil or (type(value) == "boolean" and not value) then
                ngx.log(ngx.INFO,"value is null: ",value)
                break
            else
                ngx.log(ngx.INFO,"value is set to LRU: ",value)
                c:set(key,value)
            end
        until true
    end

Will red:read_reply() lost message when PUB command send in redis is between timeout or handle logic and next read_reply ? As I know about epoll implemention, I think it will not lost in handle business logic,but I don't know about timeout error if read_reply have timeout error,will PUB message lost?

zjjott avatar Jan 09 '17 06:01 zjjott

As the Redis documentation says,

Rather, published messages are characterized into channels, without knowledge of what (if any) subscribers there may be.

Redis doesn't guarantee the delivery of published message.

So if there is something wrong happended with the subscribers(timeout or any other inner socket error), the message will be lost.

If a stronger guarantee is in need, you may need to try other mechanism to deliver your message.

spacewander avatar Jan 09 '17 07:01 spacewander

@spacewander thank you~ but actually,timeout is diffence with socket error,it is read timeout, socket is still connected ,packet in process may not lost?

zjjott avatar Jan 09 '17 09:01 zjjott

I actually have the same question than @zjjott. Did you find any answer about it in the last 10 days?

EtienneM avatar Jan 19 '17 13:01 EtienneM

@zjjott Right, only real socket errors are subject to message loss.

agentzh avatar Jan 19 '17 16:01 agentzh