@@ -40,7 +40,7 @@ class Config(dict):
4040 # 密码
4141 'REDIS_PASSWORD' : 'Password123@redis' ,
4242 # 库
43- 'REDIS_DB ' : 0 ,
43+ 'REDIS_DATABASE ' : 0 ,
4444 # 最大连接数
4545 'REDIS_MAX_CONNECTIONS' : 100
4646 }
@@ -66,18 +66,42 @@ def get_db_setting(self) -> dict:
6666 }
6767
6868 def get_cache_setting (self ):
69- return {
70- 'default' : {
71- 'BACKEND' : 'django_redis.cache.RedisCache' ,
72- 'LOCATION' : f'redis://{ self .get ("REDIS_HOST" )} :{ self .get ("REDIS_PORT" )} ' ,
73- 'OPTIONS' : {
74- 'CLIENT_CLASS' : 'django_redis.client.DefaultClient' ,
75- "DB" : self .get ("REDIS_DB" ),
76- "PASSWORD" : self .get ("REDIS_PASSWORD" ),
77- "CONNECTION_POOL_KWARGS" : {"max_connections" : int (self .get ("REDIS_MAX_CONNECTIONS" ))}
69+ if self .get ("REDIS_SENTINEL_MASTER" ):
70+ # sentinel_nodes is set by env MAXKB_REDIS_SENTINEL_NODES=192.168.1.1:26379,192.168.1.2:26379,192.168.1.3:26379
71+ sentinel_nodes = self .get ("REDIS_SENTINEL_NODES" );
72+ # TODO parse sentinel_nodes to LOCATION below
73+ return {
74+ "default" : {
75+ "BACKEND" : "django_redis.cache.RedisCache" ,
76+ "LOCATION" : [
77+ "sentinel://192.168.1.1:26379" ,
78+ "sentinel://192.168.1.2:26379" ,
79+ "sentinel://192.168.1.3:26379" ,
80+ ],
81+ "OPTIONS" : {
82+ "CLIENT_CLASS" : "django_redis.client.SentinelClient" ,
83+ "PASSWORD" : self .get ("REDIS_SENTINEL_PASSWORD" ),
84+ "DB" : self .get ("REDIS_SENTINEL_DATABASE" ) or 0 ,
85+ "SENTINEL_MASTER_NAME" : self .get ("REDIS_SENTINEL_MASTER" ),
86+ "SOCKET_TIMEOUT" : float (self .get ("REDIS_SENTINEL_SOCKET_TIMEOUT" ) or 10 ),
87+ "CONNECTION_POOL_KWARGS" : {"max_connections" : int (self .get ("REDIS_SENTINEL_MAX_CONNECTIONS" ) or 100 )}
88+ }
89+ }
90+ }
91+ else :
92+ return {
93+ 'default' : {
94+ 'BACKEND' : 'django_redis.cache.RedisCache' ,
95+ 'LOCATION' : f'redis://{ self .get ("REDIS_HOST" )} :{ self .get ("REDIS_PORT" )} ' ,
96+ 'OPTIONS' : {
97+ 'CLIENT_CLASS' : 'django_redis.client.DefaultClient' ,
98+ "DB" : self .get ("REDIS_DATABASE" ),
99+ "PASSWORD" : self .get ("REDIS_PASSWORD" ),
100+ "CONNECTION_POOL_KWARGS" : {"max_connections" : int (self .get ("REDIS_MAX_CONNECTIONS" ) or 100 )}
101+ },
78102 },
79- },
80- }
103+ }
104+
81105
82106 def get_language_code (self ):
83107 return self .get ('LANGUAGE_CODE' , 'zh-CN' )
0 commit comments