ddd*_*ddd 4 python publish-subscribe redis
我正在编写一个应用程序来获取发布到 Redis 中的通道的消息并处理它们。这是一个长期存在的应用程序,基本上从不监听频道。
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)
Run Code Online (Sandbox Code Playgroud)
当我运行该程序时,我注意到它没有获取在程序启动之前发布到通道的消息。在应用程序订阅频道后,可以很好地获取发送到频道的消息。
在生产中,很可能在程序开始之前通道中存在一些消息。有没有办法获取这些旧消息?
| 归档时间: |
|
| 查看次数: |
3971 次 |
| 最近记录: |