Skip to content

Commit

Permalink
feat: 超大订阅方案 (closed #2429)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyyalt committed Dec 13, 2024
1 parent 4d5df9c commit 2db4cc0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions apps/core/concurrent/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_from_cache(self, using: str, key: str) -> typing.Any:
data_type = func_result.split("_")[-2]
if data_type == "dict":
return RedisDict(cache_uuid_key=func_result)
else:
elif data_type == "list":
return RedisList(cache_uuid_key=func_result)

return func_result
Expand All @@ -63,14 +63,17 @@ def set_to_cache(self, using: str, key: str, value: typing.Any):

if self.uuid_cache_enable:
# 变量上下文会将原本的uuid_key删除,这里重新命名,即可达到缓存目的
new_uuid_key = None
if isinstance(value, RedisDict):
new_uuid_key = f"data_backend_redis_dict_{uuid.uuid4().hex}"
else:
elif isinstance(value, RedisList):
new_uuid_key = f"data_backend_redis_list_{uuid.uuid4().hex}"
value._update_redis_expiry(self.cache_time)
value.client.rename(value.uuid_key, new_uuid_key)
value.cache_uuid_key = new_uuid_key
value = new_uuid_key

if new_uuid_key:
value._update_redis_expiry(self.cache_time)
value.client.rename(value.uuid_key, new_uuid_key)
value.cache_uuid_key = new_uuid_key
value = new_uuid_key

cache.set(key, value, self.cache_time)

Expand Down

0 comments on commit 2db4cc0

Please sign in to comment.