我试图弄清楚 rq 使用 redis 排队。我有简单的 test_job 函数,我想在队列中使用它。
def test_job():
return "OK"
脚本主要取自 rq 文档:
#!/usr/bin/env python
import redis.client
from rq import Queue
import time
from helpers import test_job
def main():
q = Queue(connection=redis.client.Redis('localhost',6379))
job = q.enqueue(test_job)
print job.result # => None
while not job.result:
time.sleep(2)
print job.result # => None
if __name__ == "__main__":
main()
问题是我没有离开while循环。job.result 仍然没有。但是,根据日志,redis 连接似乎有效:
[1279] 30 Dec 12:08:20.041 - 0 clients connected (0 slaves), 612560 bytes in use
[1279] 30 Dec 12:08:21.371 - Accepted 127.0.0.1:58541
[1279] 30 Dec 12:08:25.337 - DB 0: 23 keys (0 volatile) in 32 slots HT.
[1279] 30 Dec 12:08:25.337 - 1 clients connected (0 slaves), 633664 bytes in use