Commit 76f7bdb3 authored by 王凯's avatar 王凯

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

刷新redis数据

See merge request !19
parents 5cc43cb3 508a9f42
<?xml version="1.0" encoding="utf-8"?>
<gm_rpcd_config>
<info config_name="deploy" version="1.0"/>
<config name="log_dir" value="/data/log/geoserver"/>
</gm_rpcd_config>
......@@ -43,6 +43,23 @@ def nearly_hospitals(q_lat,q_lng,radis=500,unit="km",count=20):
}
return data
@bind('geoserver/home/refresh')
def refresh():
'''刷新redis中数据'''
result={
"result":True,
"data":[],
"message":""
}
try:
refresh_cache_locations()
except Exception as e:
result.update({"result":False,"message":str(e)})
return result
@bind("geoserver/home/hospitals_distance")
def specify_hospitals_distance(q_lng,q_lat,hospital_ids):
'''
......@@ -51,25 +68,31 @@ def specify_hospitals_distance(q_lng,q_lat,hospital_ids):
cache_key="hospital_location"
#锁定临时的key
result=[]
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)
if not distance:
distance=0
result.append({"id":item,"distance":distance})
#排序
result=sorted(result,key=lambda x:x.get("distance"))
data=[]
message=""
result=True
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)
if not distance:
distance=0
data.append({"id":item,"distance":distance})
#排序
data=sorted(data,key=lambda x:x.get("distance"))
except Exception as e:
result,message=False,str(e)
data={
"result":True,
"data":result,
"message":""
"result":result,
"data":data,
"message":message
}
return data
......
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