Commit 326801bb authored by 吴升宇's avatar 吴升宇

strong redis key

parent 96de55f5
...@@ -116,13 +116,15 @@ def logins(user_id): ...@@ -116,13 +116,15 @@ def logins(user_id):
@shared_task(retry_kwargs={'max_retries': 0}) @shared_task(retry_kwargs={'max_retries': 0})
def click(cookies_get, id): def click(cookies_get, id):
click_key = 'click topic_id:%s, cookies_get: %s' % (str(cookies_get), str(id)) try:
cache_count = click_cache.get(click_key) click_key = 'click topic_id:%s, cookies_get: %s' % (str(cookies_get), str(id))
if cache_count: cache_count = click_cache.get(click_key)
return
else:
click_cache.set(click_key, 1) click_cache.set(click_key, 1)
click_cache.expire(click_key, settings.CACHE_SECONDS) click_cache.expire(click_key, settings.CACHE_SECONDS)
if cache_count:
return
except:
return
# 点赞 # 点赞
try: try:
...@@ -158,13 +160,16 @@ def click(cookies_get, id): ...@@ -158,13 +160,16 @@ def click(cookies_get, id):
@shared_task(retry_kwargs={'max_retries': 0}) @shared_task(retry_kwargs={'max_retries': 0})
def reply(cookies_get, id, content): def reply(cookies_get, id, content):
reply_key = 'click topic_id:%s, cookies_get: %s, content:%s' % (str(id), str(cookies_get), str(content)) try:
cache_count = reply_cache.get(reply_key) reply_key = 'click topic_id:%s, cookies_get: %s, content:%s' % (str(id), str(cookies_get), str(content))
if cache_count: cache_count = reply_cache.get(reply_key)
return
else:
reply_cache.set(reply_key, 1) reply_cache.set(reply_key, 1)
reply_cache.expire(reply_key, settings.CACHE_SECONDS) reply_cache.expire(reply_key, settings.CACHE_SECONDS)
if cache_count:
return
except:
return
try: try:
post_dict = { post_dict = {
'topic_id': id, 'topic_id': id,
...@@ -289,13 +294,16 @@ def get_comments(): ...@@ -289,13 +294,16 @@ def get_comments():
@shared_task(retry_kwargs={'max_retries': 0}) @shared_task(retry_kwargs={'max_retries': 0})
def follow(cookies_get, id): def follow(cookies_get, id):
follow_key = 'click user_id:%s, cookies_get: %s' % (str(id), str(cookies_get)) try:
cache_count = follow_cache.get(follow_key) follow_key = 'click user_id:%s, cookies_get: %s' % (str(id), str(cookies_get))
if cache_count: cache_count = follow_cache.get(follow_key)
return
else:
follow_cache.set(follow_key, 1) follow_cache.set(follow_key, 1)
follow_cache.expire(follow_key, settings.CACHE_SECONDS) follow_cache.expire(follow_key, settings.CACHE_SECONDS)
if cache_count:
return
except:
return
try: try:
post_dict = { post_dict = {
'type': 1, 'type': 1,
...@@ -462,14 +470,17 @@ def set_reply_to_redis(): ...@@ -462,14 +470,17 @@ def set_reply_to_redis():
@shared_task(retry_kwargs={'max_retries': 0}) @shared_task(retry_kwargs={'max_retries': 0})
def reply2(cookies_get, id, content, replied_id): def reply2(cookies_get, id, content, replied_id):
reply_key = 'click topic_id:%s, cookies_get: %s, content:%s, replied_id: %s' % \ try:
(str(id), str(cookies_get), str(content), str(replied_id)) reply_key = 'click topic_id:%s, cookies_get: %s, content:%s, replied_id: %s' % \
cache_count = reply_cache.get(reply_key) (str(id), str(cookies_get), str(content), str(replied_id))
if cache_count: cache_count = reply_cache.get(reply_key)
return
else:
reply_cache.set(reply_key, 1) reply_cache.set(reply_key, 1)
reply_cache.expire(reply_key, settings.CACHE_SECONDS) reply_cache.expire(reply_key, settings.CACHE_SECONDS)
if cache_count:
return
except:
return
try: try:
post_dict = { post_dict = {
'topic_id': id, 'topic_id': id,
...@@ -491,13 +502,16 @@ def reply2(cookies_get, id, content, replied_id): ...@@ -491,13 +502,16 @@ def reply2(cookies_get, id, content, replied_id):
@shared_task(retry_kwargs={'max_retries': 0}) @shared_task(retry_kwargs={'max_retries': 0})
def pictorial_reply(cookies_get, id, content): def pictorial_reply(cookies_get, id, content):
reply_key = 'click topic_id:%s, cookies_get: %s, content:%s' % (str(id), str(cookies_get), str(content)) try:
cache_count = reply_cache.get(reply_key) reply_key = 'click topic_id:%s, cookies_get: %s, content:%s' % (str(id), str(cookies_get), str(content))
if cache_count: cache_count = reply_cache.get(reply_key)
return
else:
reply_cache.set(reply_key, 1) reply_cache.set(reply_key, 1)
reply_cache.expire(reply_key, settings.CACHE_SECONDS) reply_cache.expire(reply_key, settings.CACHE_SECONDS)
if cache_count:
return
except:
return
try: try:
post_dict = { post_dict = {
'pictorial_id': id, 'pictorial_id': id,
......
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