Commit df5ddaaf authored by 赵威's avatar 赵威

write data to redis

parent b2efe798
...@@ -73,21 +73,17 @@ def get_tractate_vector(sentence_lst, all_keywords_set, model): ...@@ -73,21 +73,17 @@ def get_tractate_vector(sentence_lst, all_keywords_set, model):
def save_tractate_vector_to_redis(all_keywords_set, model): def save_tractate_vector_to_redis(all_keywords_set, model):
es_result = get_new_user_tractate_info() es_result = get_new_user_tractate_info()
count = 0 count = 0
res = {}
redis_key = "rims:tractate:sentense:vector:new_user"
for i in es_result: for i in es_result:
count += 1 count += 1
source = i["_source"] source = i["_source"]
sentences = source["keynote_sentence"] sentences = source["keynote_sentence"]
id = source["id"] id = source["id"]
vec = get_tractate_vector(sentences, all_keywords_set, model) vec = get_tractate_vector(sentences, all_keywords_set, model)
redis_key = "rims:tractate:sentense:vector:" + str(id)
if vec: if vec:
print(count, id, len(vec)) print(count, id, len(vec))
res[id] = vec redis_client5.set(redis_key, json.dumps(vec))
if res: # redis_client5.expire(redis_key, 60 * 60 * 24 * 3)
redis_client5.set(redis_key, json.dumps(res))
# TODO remove
redis_client5.expire(redis_key, 60 * 60 * 24 * 3)
def save_tag_vector_to_redis(all_tags_lst, model): def save_tag_vector_to_redis(all_tags_lst, model):
...@@ -101,8 +97,7 @@ def save_tag_vector_to_redis(all_tags_lst, model): ...@@ -101,8 +97,7 @@ def save_tag_vector_to_redis(all_tags_lst, model):
redis_key = "rims:tractate:tags:vector" redis_key = "rims:tractate:tags:vector"
if res: if res:
redis_client5.set(redis_key, json.dumps(res)) redis_client5.set(redis_key, json.dumps(res))
# TODO remove # redis_client5.expire(redis_key, 60 * 60 * 24 * 3)
redis_client5.expire(redis_key, 60 * 60 * 24 * 3)
print("tags vector redis: " + str(len(res))) print("tags vector redis: " + str(len(res)))
......
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