Skip to content

Pub/sub bug on multi subscribe? #193

@vstath

Description

@vstath

Hello,

perhaps I'm misusing the lua-resty-redis but I have a repeatable problem when I try to subscribe sequentially to multiple redis channels as needed.

The "subscribe" command of Redis allows one to do something like

"subscribe channelname"

Once the client enters the subscribed state it is not supposed to issue any other commands, except for additional SUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE, PUNSUBSCRIBE, PING and QUIT commands.

So my flow is

subscribe control-channel

subscribe channel-1

subscribe channel-2

Although this works fine when doing direct telnet to redis, I get unpredictable results when using lua-resty-redis. The response some times is the actual Redis protocol. I have a simple command line example that demonstrates the issue.

File "red_sub.lua"

local redis = require "resty.redis" -- local cjson = require "cjson" local red = redis:new() local ok, err = red:connect("127.0.0.1", 6379) if err then print("Failed: " .. err) end if ok then local sub, sub_err = red:subscribe("control") while true do local res, err = red:read_reply() -- ngx.say(cjson.encode(res)) red:subscribe(res[3]) end end 

runs with "resty red_sub.lua"

Afterwards you need to run the next file

File "red_pub.lua"

local redis = require "resty.redis" -- local cjson = require "cjson" local red = redis:new() local ok, err = red:connect("127.0.0.1", 6379) if err then print("Failed: " .. err) end if ok then local i = 1 while i <= 20 do local res, err = red:publish("control", "ch-" .. i) i = i + 1 end end 

runs with "resty red_pub.lua" after the "red_sub.lua" has started.

Then if you do "redis-cli MONITOR" you can see that some requests are "subscribe ch-[1..20]" but some are not and if you print the result of red:read_reply() you will see that the RESP (redis protocol) is returned :-(

Thank you for your excellent software and I hope some experienced developer can check if this is a bug in the library?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions