Commit 03a476d2 authored by gaoming's avatar gaoming

fix

parent 508a9f42
......@@ -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
#将地理位置信息加入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