windows 安装redis 使用celery

redis默认端口是6379可以不写,改掉默认端口,就得写上

redis下载地址
https://github.com/tporadowski/redis/releases

运行方法,进入到redis目录cmd命令执行

redis-server.exe redis.windows.conf

在虚拟环境cmd执行celery worker命令
windows下安装eventlet

(venv) H:\code_test\c2>celery -A tasks.celery worker --pool=eventlet

eventlet出现问题可以用solo替换,linux环境不用配置pool

celery -A tasks.celery worker --pool=solo --loglevel=info

main.py

from tasks import send_mail

if __name__ == '__main__':

    send_mail.delay()

tasks.py

from celery import Celery
import time

celery = Celery('tasks', broker='redis://127.0.0.1/0', backend='redis://127.0.0.1/0')

@celery.task
def send_mail():
    print('开始发送邮件')
    time.sleep(5)
    print('结束邮件发送')

你可能感兴趣的:(windows,python,redis,windows,缓存)