Commit 1b43277a authored by 段英荣's avatar 段英荣

modify

parent 742bdca7
...@@ -36,7 +36,7 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10): ...@@ -36,7 +36,7 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10):
unread_topic_id_list = list() unread_topic_id_list = list()
have_read_topic_id_tuple = set() have_read_topic_id_tuple = set()
if len(redis_val_dict)>0 and offset>0 and user_id>0 and offset==(last_offset_num+1): if len(redis_val_dict)>0 and offset>0 and user_id>0 and offset==last_offset_num:
topic_id_list = redis_val_dict[b"unread_topic_id"] + topic_id_list topic_id_list = redis_val_dict[b"unread_topic_id"] + topic_id_list
have_read_topic_id_tuple = set(redis_val_dict[b"have_read_topic_id"]) have_read_topic_id_tuple = set(redis_val_dict[b"have_read_topic_id"])
for item in topic_id_list: for item in topic_id_list:
...@@ -61,7 +61,7 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10): ...@@ -61,7 +61,7 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10):
redis_dict = { redis_dict = {
"unread_topic_id":json.dumps(unread_topic_id_list), "unread_topic_id":json.dumps(unread_topic_id_list),
"have_read_topic_id":json.dumps(list(have_read_topic_id_tuple)), "have_read_topic_id":json.dumps(list(have_read_topic_id_tuple)),
"last_offset_num":offset "last_offset_num":offset+size
} }
redis_client.hmset(redis_key,redis_dict) redis_client.hmset(redis_key,redis_dict)
# 每个session key保存15分钟 # 每个session key保存15分钟
...@@ -89,7 +89,7 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10): ...@@ -89,7 +89,7 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10):
user_id=-1 user_id=-1
if not isinstance(session_id,str): if not isinstance(session_id,str):
session_id = "" session_id = ""
redis_key = "physical:home_query" + ":user_id:" + str(user_id) + ":session_id:" + session_id redis_key = "physical:home_query" + ":user_id:" + str(user_id) + ":session_id:" + session_id + ":query:" + str(query).encode("utf-8")
redis_val_dict = redis_client.hgetall(redis_key) redis_val_dict = redis_client.hgetall(redis_key)
last_offset_num = redis_val_dict["last_offset_num"] if "last_offset_num" in redis_val_dict else -1 last_offset_num = redis_val_dict["last_offset_num"] if "last_offset_num" in redis_val_dict else -1
...@@ -100,7 +100,7 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10): ...@@ -100,7 +100,7 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10):
unread_topic_id_list = list() unread_topic_id_list = list()
have_read_topic_id_tuple = set() have_read_topic_id_tuple = set()
if len(redis_val_dict)>0 and offset>0 and user_id>0 and offset==(last_offset_num+1): if len(redis_val_dict)>0 and offset>0 and user_id>0 and offset==last_offset_num:
topic_id_list = json.loads(redis_val_dict[b"unread_topic_id"]) + topic_id_list topic_id_list = json.loads(redis_val_dict[b"unread_topic_id"]) + topic_id_list
have_read_topic_id_tuple = set(json.loads(redis_val_dict[b"have_read_topic_id"])) have_read_topic_id_tuple = set(json.loads(redis_val_dict[b"have_read_topic_id"]))
for item in topic_id_list: for item in topic_id_list:
...@@ -125,7 +125,7 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10): ...@@ -125,7 +125,7 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10):
redis_dict = { redis_dict = {
"unread_topic_id":json.dumps(unread_topic_id_list), "unread_topic_id":json.dumps(unread_topic_id_list),
"have_read_topic_id":json.dumps(list(have_read_topic_id_tuple)), "have_read_topic_id":json.dumps(list(have_read_topic_id_tuple)),
"last_offset_num":offset "last_offset_num":offset+size
} }
redis_client.hmset(redis_key,redis_dict) redis_client.hmset(redis_key,redis_dict)
# 每个session key保存15分钟 # 每个session key保存15分钟
......
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