简体   繁体   English

在 Python 中使用 redis

[英]Using redis in Python

How can I use celery thats its expire time is 60sec using celery?我如何使用 celery,即它的到期时间是 60 秒,使用 celery?

from bs4 import BeautifulSoup
import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
}

def weather(cities):
    results = []
    for city in cities:
        res = requests.get(f'https://www.google.com/search?q={city} weather&oq={city} weather&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&sourceid=chrome&ie=UTF-8', headers=headers)
        soup = BeautifulSoup(res.text, 'html.parser')
        weather = soup.select('#wob_tm')[0].getText().strip()
        results.append({city: weather})
    return results

cities = ["tehran" , "Mashhad","Shiraaz","Semirom","Ahvaz","zahedan","baghdad","van","herat","sari"]
weather_data = weather(cities)
print(weather_data)
def temporary_city(city):
    
res = requests.get(f'https://www.google.com/search?q={city} weather&oq={city} weather&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&sourceid=chrome&ie=UTF-8', headers=headers)    
return res

I cannot understand your problem about celery (Celery is a task queue not a cache memory) You can use Official Celery Documentation to use celery in python Also if you want to use Redis as cache,I think this article is helpful and solves your problem.我无法理解你关于 celery 的问题(Celery 是一个任务队列而不是缓存)你可以使用官方 Celery 文档在 python 中使用 celery 另外如果你想使用 Redis 作为缓存,我认为这篇文章很有帮助并解决了你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM