Преглед на файлове

优化查询设备天气接口

peng преди 2 години
родител
ревизия
3c61a4b802
променени са 1 файла, в които са добавени 5 реда и са изтрити 5 реда
  1. 5 5
      Controller/WeatherControl.py

+ 5 - 5
Controller/WeatherControl.py

@@ -51,14 +51,14 @@ class WeatherView(View):
         redis_obj = RedisObject()
         city_id = uid_set_qs[0]['tb_city_information_id']
         try:
-            temp = redis_obj.get_data('city_id_{}_temp'.format(city_id))
-            humidity = redis_obj.get_data('city_id_{}_humidity'.format(city_id))
-            if not all([temp, humidity]):
+            weather = redis_obj.get_data('city_id_{}_weather'.format(city_id))
+            if weather:
+                temp, humidity = weather.split('/')
+            else:
                 city_obj = WeatherInfo(city_id)
                 temp, humidity = city_obj.get_city_weather()
                 if temp and humidity:
-                    redis_obj.set_ex_data('city_id_{}_temp'.format(city_id), temp, 600)
-                    redis_obj.set_ex_data('city_id_{}_humidity'.format(city_id), humidity, 600)
+                    redis_obj.set_ex_data('city_id_{}_weather'.format(city_id), '{}/{}'.format(temp, humidity), 600)
             if not all([temp, humidity]):
                 return response.json(10, '获取天气失败')
             return response.json(0, {'temp': temp, 'humidity': humidity})