Commit 06dc1ba0 authored by 王凯's avatar 王凯

Merge branch '刷新数据' into 'meilai'

刷新数据

See merge request !21
parents 76f7bdb3 2c9fceb5
......@@ -19,7 +19,7 @@ def refresh_cache_locations():
locations = rpc_client['api/hospital/location']().unwrap()
cache_key="hospital_location"
cache_diuration=24*60*60
cache_diuration=60*10
#将地理位置信息加入redis缓存
for item in locations:
lat=item.get("baidu_loc_lat") if item.get("baidu_loc_lat") else item.get("google_loc_lat")
......
......@@ -72,13 +72,18 @@ def specify_hospitals_distance(q_lng,q_lat,hospital_ids):
message=""
result=True
cache_key="hospital_location"
if not r.exists(cache_key):
refresh_cache_locations()
try:
temp_key="hospital_location_temp"
lock_key="hospital_location_lock"
with r.lock(lock_key, blocking_timeout=15) as lock:
r.geoadd(cache_key,float(q_lng),float(q_lat),temp_key)
for item in hospital_ids:
distance=r.geodist(cache_key,temp_key,item)
distance=r.geodist(cache_key,temp_key,item,"km")
if not distance:
distance=0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment