Redis publish不能在Flask中工作

2024-04-18 14:48:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我在缓存文件中有一个Redis客户端:

from redis import Redis

client = Redis(host='0.0.0.0', port=6379, db=0)

我用来订阅任务文件:

from cache import client

pubsub = client.pubsub()

def show(message):
    print(message.get('data'))

pubsub.subscribe(**{'msg': show})

然后在服务器文件的Flask路由中,我在频道msg中发布一条消息:

from cache import client

client.publish(
    'msg',
    '( :'
)

但是当我向路由发出请求时,什么也没有发布,或者什么也没有显示。我已经试过查看日志,阅读documentation,使用execute command,看起来类似example,等等,但是都没用。下面是code到更详细的上下文。有什么建议吗?你知道吗

Obs:正如您在Github存储库的代码中看到的,subscribe和publish在不同的线程中


Tags: 文件fromimportredisclient客户端路由cache