Merge branch 'master' of http://192.168.0.27/dev0/PriceSystem
修改: PriceSystem/config/__init__.py 修改: PriceSystem/fangjia/__init__.py 新文件: PriceSystem/fangjia/cachedObjectWrapper.py 修改: PriceSystem/ones_Sender.py 修改: PriceSystem/test.py
This commit is contained in:
@@ -18,6 +18,10 @@ def get_redis_db():
|
||||
return 1
|
||||
|
||||
|
||||
def get_redis_cache_db():
|
||||
return 2
|
||||
|
||||
|
||||
def get_mongodb_host():
|
||||
return "mongo.db.fangjia.com"
|
||||
|
||||
|
||||
@@ -7,8 +7,11 @@ import datetime
|
||||
import calendar
|
||||
import requests
|
||||
import json
|
||||
import pickle
|
||||
import redis
|
||||
from fangjia import mongoClients as mongoClients
|
||||
from fangjia import ElasticsearchClient as es
|
||||
from fangjia.cachedObjectWrapper import CachedObjectWrapper
|
||||
|
||||
formatter = logging.Formatter('%(processName)s %(asctime)s %(name)-6s %(levelname)-6s %(message)s')
|
||||
|
||||
@@ -64,6 +67,37 @@ def timer(func):
|
||||
return _timer
|
||||
|
||||
|
||||
QUEUE = "price_system"
|
||||
redis_pool = redis.ConnectionPool(host=config.get_redis_host(), port=6379, db=config.get_redis_cache_db())
|
||||
client = redis.Redis(connection_pool=redis_pool)
|
||||
|
||||
|
||||
def cache(expire=None):
|
||||
def _cache(func):
|
||||
def __cache(*args, **kw):
|
||||
arg_list = list()
|
||||
for arg in args:
|
||||
arg_list.append(str(arg))
|
||||
key = func.__name__ + "_" + "_".join(arg_list)
|
||||
try:
|
||||
val = client.hget(QUEUE, key)
|
||||
if val is not None:
|
||||
wrapper = pickle.loads(val)
|
||||
if not wrapper.is_expire():
|
||||
return wrapper.val
|
||||
else:
|
||||
client.hset(QUEUE, key, None)
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
rs = func(*args, **kw)
|
||||
wrapper = CachedObjectWrapper(rs, time.time(), expire)
|
||||
client.hset(QUEUE, key, pickle.dumps(wrapper))
|
||||
return rs
|
||||
return __cache
|
||||
|
||||
return _cache
|
||||
|
||||
|
||||
def get_collection(db, name, host="192.168.0.136", port=27017):
|
||||
return mongoClients.MongoClients(db, name, host, port).collection
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import time
|
||||
|
||||
|
||||
class CachedObjectWrapper:
|
||||
|
||||
def __init__(self, val, timestamp, cached_time=None):
|
||||
self.val = val
|
||||
self.timestamp = timestamp
|
||||
self.cached_time = cached_time
|
||||
|
||||
def is_expire(self):
|
||||
return self.cached_time is not None and time.time() > self.cached_time + self.timestamp
|
||||
@@ -41,5 +41,10 @@ def get_weekend(tt):
|
||||
|
||||
if __name__ == "__main__":
|
||||
weekend = ""
|
||||
<<<<<<< HEAD
|
||||
send_cmd({"city": "西安", "region": "雁塔", "name": "鸿景花园", "weekend": get_weekend('20180325')})
|
||||
#sys.exit(0)
|
||||
=======
|
||||
send_cmd({"city": "西安", "region": "未央", "name": "兴乐园", "weekend": get_weekend('20180325')})
|
||||
sys.exit(0)
|
||||
>>>>>>> 4025e7533b2d0abe68b929bfb7d7c01b201fc112
|
||||
|
||||
+12
-4
@@ -37,16 +37,16 @@ lk = '会展世界城三期'
|
||||
ct='西安'
|
||||
rl='雁塔'
|
||||
lk='鸿景花园'
|
||||
#成都双流长滩一号 上海 奉贤 朝阳新村
|
||||
#成都双流长滩一号 上海 奉贤 朝阳新村##
|
||||
|
||||
|
||||
#未央
|
||||
|
||||
#weekend = datetime.datetime.strptime("2018-03-11", "%Y-%m-%d")
|
||||
#for i in range(0, 100):
|
||||
sellPrice.out_put_price(ct, rl, lk, fangjia.get_weekend())
|
||||
e = time.time()
|
||||
print(e - s)
|
||||
# sellPrice.out_put_price(ct, rl, lk, fangjia.get_weekend())
|
||||
# e = time.time()
|
||||
# print(e - s)
|
||||
'''
|
||||
###
|
||||
import pandas as pd
|
||||
@@ -61,3 +61,11 @@ for i in a.index:
|
||||
|
||||
'''
|
||||
|
||||
|
||||
@fangjia.cache(1000)
|
||||
def sum1(a, b):
|
||||
print(111)
|
||||
return a + b
|
||||
|
||||
|
||||
print(sum1(1,2))
|
||||
|
||||
Reference in New Issue
Block a user