Can I send a SUBSCRIBE command using a context that's blocked on redisGetReply #1078
-
I see that "a redisContext is not thread-safe" according to <hiredis/README.md>, but I also see the following comment in https://redis.io/commands/subscribe/:
I tried running the following test and it seems to work for me:
Now, does hiredis support a call to redisCommand(SUBSCRIBE) on a context that's blocked on redisGetReply()? Alternatively, I have looked into calling redisSetTimeout() before redisGetReply(), however after calling redisReconnect() I noticed that all the subscribed channels were reset/gone. It would be messy for me to try and re-subscribe to all the channels again. I have not looked into the Asynchronous API yet, as the Synchronous API fits in much better with our application. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi, thanks for the question. Although this may work sometimes, it will inevitably lead to undefined behavior and fail in strange and difficult-to-predict ways. The reason for this is that two independent threads will be attempting to operate on the same shared internal context and hiredis does not do any synchronization internally. The async API can do what you need, and we actually recently merged a polling adapter, which would allow you to use it without having to add an event library to your application. The adapter in question Another solution could possibly be to |
Beta Was this translation helpful? Give feedback.
-
Hi Michael, Thank you for your response, that really clears things up! I like your suggestion on using another PUBLISH message, which I'll look into further. |
Beta Was this translation helpful? Give feedback.
Hi, thanks for the question.
Although this may work sometimes, it will inevitably lead to undefined behavior and fail in strange and difficult-to-predict ways.
The reason for this is that two independent threads will be attempting to operate on the same shared internal context and hiredis does not do any synchronization internally.
The async API can do what you need, and we actually recently merged a polling adapter, which would allow you to use it without having to add an event library to your application.
The adapter in question
An example program that uses it
Another solution could possibly be to
PUBLISH
a message to the blocked client with some kind of special payload that would infor…