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):
if __name__ == "__main__":
# TODO 如果耗时小于一分钟,下一次取到的device_id和上一次相同
while True:
start = time.time()
empty,device_id_list = get_active_users()
if empty:
time.sleep(10)
else:
for device_id in device_id_list:
router(device_id)
end = time.time()
time_cost = (end - start)
print("预测耗时{}秒".format(time_cost))
router('358035085192742')
# while True:
# start = time.time()
# empty,device_id_list = get_active_users()
# if empty:
# time.sleep(10)
# else:
# for device_id in device_id_list:
# router(device_id)
#
# end = time.time()
# time_cost = (end - start)
# print("预测耗时{}秒".format(time_cost))
......@@ -15,25 +15,12 @@ def con_sql(sql):
db.close()
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里
def add_data_to_redis(key,val):
db = Database()
db.add_write(key,val)
db.batch_write()
r = redis.StrictRedis(host='10.30.50.58', port=6379, db = 12)
r.set(key, val)
# 设置key的过期时间
r.expire(key,36*60)
# 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