redis的轻量级队列

To put jobs on queues, you don’t have to do anything special, just define your typically lengthy or blocking function:

import requests

def count_words_at_url(url):
    """Just an example function that's called async."""
    resp = requests.get(url)
    return len(resp.text.split())

You do use the excellent requests package, don’t you?

Then, create an RQ queue:

from redis import Redis
from rq import Queue

q = Queue(connection=Redis())
And enqueue the function call:

from my_module import count_words_at_url
job = q.enqueue(count_words_at_url, 'http://nvie.com')

猜你喜欢

转载自blog.csdn.net/wu0che28/article/details/83035969