feat: use redis cache (#3185)
This commit is contained in:
parent
c2e9e5480a
commit
d92fdb999c
@ -29,6 +29,16 @@ class Config(dict):
|
|||||||
# 语言
|
# 语言
|
||||||
'LANGUAGE_CODE': 'zh-CN',
|
'LANGUAGE_CODE': 'zh-CN',
|
||||||
"DEBUG": False,
|
"DEBUG": False,
|
||||||
|
# redis 目前先支持单机 哨兵的配置后期加上
|
||||||
|
'REDIS_HOST': '127.0.0.1',
|
||||||
|
# 端口
|
||||||
|
'REDIS_PORT': 6379,
|
||||||
|
# 密码
|
||||||
|
'REDIS_PASSWORD': 'Password123@redis',
|
||||||
|
# 库
|
||||||
|
'REDIS_DB': 0,
|
||||||
|
# 最大连接数
|
||||||
|
'REDIS_MAX_CONNECTIONS': 100
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_debug(self) -> bool:
|
def get_debug(self) -> bool:
|
||||||
@ -52,11 +62,17 @@ class Config(dict):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_cache_setting():
|
def get_cache_setting(self):
|
||||||
return {
|
return {
|
||||||
'default': {
|
'default': {
|
||||||
'BACKEND': 'diskcache.DjangoCache',
|
'BACKEND': 'django_redis.cache.RedisCache',
|
||||||
'LOCATION': f'{PROJECT_DIR}/data/cache'
|
'LOCATION': f'redis://{self.get("REDIS_HOST")}:{self.get("REDIS_PORT")}',
|
||||||
|
'OPTIONS': {
|
||||||
|
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
||||||
|
"DB": self.get("REDIS_DB"),
|
||||||
|
"PASSWORD": self.get("REDIS_PASSWORD"),
|
||||||
|
"CONNECTION_POOL_KWARGS": {"max_connections": int(self.get("REDIS_MAX_CONNECTIONS"))}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user