-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Behavior of Subscriber::consume() #240
Comments
Hi @vcampmany Could you also please run the following command in the directory that you built redis-plus-plus, in order to see if all tests passed? Like so: $ ./test/test_redis++ -h localhost -p 6379
Testing Redis...
Pass sanity tests
Pass connection commands tests
Pass keys commands tests
Pass string commands tests
Pass list commands tests
Pass hash commands tests
Pass set commands tests
Pass zset commands tests
Pass hyperloglog commands tests
Pass geo commands tests
Pass script commands tests
Pass pubsub tests
Pass pipeline and transaction tests
Pass stream commands tests
Pass all tests Lastly, please take a look at the following pub-sub unit test file for more examples: Thanks & regards |
@vcampmany The subscribe operation, i.e. consume method, blocks until there is new message published to channel, or the connection is timeout. If you want to mitigate the problem, you can set a small socket_timeout, say, 10ms. It will block at most 10ms, note the timeout might also depends on the precision of system clock. Regards |
Thanks for your replies @sewenew and @wingunder. I spotted the problem and it was on my side. I wasn't setting the socket_timeout correctly. As a follow up question: I have a Right now I have something like this: ConnectionOptions opts;
opts.host = "host";
opts.port = 6379;
Redis r(opts)
// ...
// Use r
// ...
ConnectionOptions sub_opts = opts;
sub_opts.socket_timeout = 100ms;
Subscriber sub = Redis(sub_opts).subscriber() Thanks! |
Hi @vcampmany
It's funny, I also stumbled across this before. I ended up using a Redis instance per uniquely required timeout. This is expensive, but you can (and should) reuse the Redis instances. If you have say, 3 subscribes with a 10 sec timeout and 50 subscribes with a 3 second timeout, you'll only need to have 2 Redis instances. I however do not know how of another way to solve this. Maybe @sewenew has some better ideas. |
Yes, as @wingunder mentioned, you need to create another Redis object with different connection options. So far, there's no way to reset the connection options for subscriber. There's a plan to share the connection between Regards |
Thanks for clarifying @sewenew. Closing the issue as doubts are resolved. Regards |
A similar issue is covered in #307, with a good explanation and example, by @sewenew. |
I'm trying to implement a subscriber, I have a code that looks as follows:
When I run this code, it usually runs as expected. Meaning, once in the
while
loop it tries to consume a message, if no message is available, it goes on to the next iteration (I can see the message printed out in console). However, for some executions, after a few iterations, it seems like theSubscriber::consume()
methods blocks (i.e. I stop seeing new lines printed in the console). I've been able to "unblock" it by sending aPUBLISH
command fromredis-cli
, which wakes up the consume method and the program continues execution.The "blocking" of
Subscriber::consume()
seems to happen randomly. I was wondering what is the behavior of the method, I couldn't find more details in the documentation. I've been playing withsocket_timeout
from ConnectionOptions, but that didn't make any difference. Some help would be much appreciated 🙂Thanks for this awesome library!
The text was updated successfully, but these errors were encountered: