sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.64k stars 351 forks source link

[QUESTION] Any loss of message in time between sub.consume and callback #424

Closed sknagappan closed 1 year ago

sknagappan commented 1 year ago

when the message is received, Subscriber::consume calls the callback function to process the messages, during this time, will sub.consume() continue to receive the message without losing any messages? Assume the callback takes longer time to return, even during this time, messages arriving on channels are in queue and its not dropped? consume() returns after consume() calls the callback on receiving the message. from the time consume() returns and till next consume, what happens to the messages?

sewenew commented 1 year ago

Subscriber::consume() does 2 things:

  1. receive message from Redis
  2. then call the registered callback

Receiving message and running callback are not run in parallel.

Client does not receive new message until consume finishes the callback and returns. Only when you call consume again (normally in a loop), client receives new messages. So there's no messages lost.

Regards

wingunder commented 1 year ago

Please also refer to the following thread and comment, regarding the Subscriber class' thread safety: https://github.com/sewenew/redis-plus-plus/issues/289#issuecomment-959374839