I am writing an application to get messages published to a channel in Redis and process them. It is a long-lived app which never basically listens to the channel.
def msg_handler():
r = redis.client.StrictRedis(host='localhost', port=6379, db=0)
sub = r.pubsub()
sub.subscribe(settings.REDIS_CHANNEL)
while True:
msg = sub.get_message()
if msg:
if msg['type'] == 'message':
print(msg)
def main():
for i in range(3):
t = threading.Thread(target=msg_handler, name='worker-%s' % i)
print('thread {}'.format(i))
t.setDaemon(True)
t.start()
while True:
print('Waiting')
time.sleep(1)
When I run this program, I notice that it is not getting messages that were published to the channel before the the program started. It works fine to get messages sent to the channel after the app subscribing to the channel.
In production, it is very likely there are some messages in the channel before the program starts. Is there a way to get these old messages?