File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed
Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -78,12 +78,26 @@ def get_cache_setting(self):
7878 },
7979 }
8080 if self .get ('REDIS_SENTINEL_SENTINELS' ) is not None :
81- del redis_config ['default' ]['LOCATION' ]
82- redis_config ['default' ]['OPTIONS' ]['SENTINEL_SENTINELS' ] = self .get ('REDIS_SENTINEL_SENTINELS' ).split (',' )
83- redis_config ['default' ]['OPTIONS' ]['SENTINEL_MASTER_SET' ] = self .get ('REDIS_SENTINEL_MASTER_SET' )
84- return redis_config
85- else :
86- return redis_config
81+ sentinels_str = self .get ('REDIS_SENTINEL_SENTINELS' )
82+ sentinels = [
83+ (host .strip (), int (port ))
84+ for hostport in sentinels_str .split (',' )
85+ for host , port in [hostport .strip ().split (':' )]
86+ ]
87+
88+ redis_config ['default' ]['LOCATION' ] = f'redis://{ self .get ("REDIS_SENTINEL_MASTER" )} /{ self .get ("REDIS_DB" )} '
89+ redis_config ['default' ]['OPTIONS' ].update ({
90+ 'CLIENT_CLASS' : 'django_redis.client.SentinelClient' ,
91+ 'SENTINELS' : sentinels ,
92+ 'SENTINEL_MASTER' : self .get ('REDIS_SENTINEL_MASTER' ),
93+ 'PASSWORD' : self .get ("REDIS_PASSWORD" ),
94+ 'SOCKET_TIMEOUT' : 1 ,
95+ })
96+
97+ # 必须移除和 Sentinel 不兼容的项
98+ redis_config ['default' ]['OPTIONS' ].pop ('CONNECTION_POOL_KWARGS' , None )
99+
100+ return redis_config
87101
88102 def get_language_code (self ):
89103 return self .get ('LANGUAGE_CODE' , 'zh-CN' )
Original file line number Diff line number Diff line change 172172DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
173173
174174edition = 'CE'
175+
176+ if os .environ .get ('MAXKB_REDIS_SENTINEL_SENTINELS' ) is not None :
177+ DJANGO_REDIS_CONNECTION_FACTORY = "django_redis.pool.SentinelConnectionFactory"
You can’t perform that action at this time.
0 commit comments