Commit 5b36cb84 authored by 张彦钊's avatar 张彦钊

modify add_data_to_redis,change main for test

parent b1a057d2
...@@ -90,16 +90,17 @@ def router(device_id): ...@@ -90,16 +90,17 @@ def router(device_id):
if __name__ == "__main__": if __name__ == "__main__":
# TODO 如果耗时小于一分钟,下一次取到的device_id和上一次相同 # TODO 如果耗时小于一分钟,下一次取到的device_id和上一次相同
while True: router('358035085192742')
start = time.time() # while True:
empty,device_id_list = get_active_users() # start = time.time()
if empty: # empty,device_id_list = get_active_users()
time.sleep(10) # if empty:
else: # time.sleep(10)
for device_id in device_id_list: # else:
router(device_id) # for device_id in device_id_list:
# router(device_id)
end = time.time() #
time_cost = (end - start) # end = time.time()
print("预测耗时{}秒".format(time_cost)) # time_cost = (end - start)
# print("预测耗时{}秒".format(time_cost))
...@@ -15,25 +15,12 @@ def con_sql(sql): ...@@ -15,25 +15,12 @@ def con_sql(sql):
db.close() db.close()
return df return df
class Database:
def __init__(self):
self.host = '10.30.50.58'
self.port = 6379
self.db = 12
self.write_pool = {}
def add_write(self, key,val):
self.write_pool[key] = val
def batch_write(self):
r = redis.StrictRedis(host=self.host, port=self.port, db= self.db)
r.mset(self.write_pool)
# 把数据写到redis里 # 把数据写到redis里
def add_data_to_redis(key,val): def add_data_to_redis(key,val):
db = Database() r = redis.StrictRedis(host='10.30.50.58', port=6379, db = 12)
db.add_write(key,val) r.set(key, val)
db.batch_write() # 设置key的过期时间
r.expire(key,36*60)
# ffm 格式转换函数、类 # ffm 格式转换函数、类
......
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