7
7
8
8
namespace Magento \MagentoCloud \Config \Factory ;
9
9
10
+ use Magento \MagentoCloud \Config \ConfigException ;
10
11
use Magento \MagentoCloud \Config \ConfigMerger ;
11
12
use Magento \MagentoCloud \Config \Stage \DeployInterface ;
12
13
use Magento \MagentoCloud \Service \Redis ;
@@ -20,18 +21,18 @@ class Cache
20
21
/**
21
22
* Redis database to store default cache data
22
23
*/
23
- const REDIS_DATABASE_DEFAULT = 1 ;
24
+ public const REDIS_DATABASE_DEFAULT = 1 ;
24
25
25
26
/**
26
27
* Redis database to store page cache data
27
28
*/
28
- const REDIS_DATABASE_PAGE_CACHE = 2 ;
29
+ public const REDIS_DATABASE_PAGE_CACHE = 2 ;
29
30
30
- const REDIS_BACKEND_CM_CACHE = 'Cm_Cache_Backend_Redis ' ;
31
- const REDIS_BACKEND_REDIS_CACHE = '\Magento\Framework\Cache\Backend\Redis ' ;
32
- const REDIS_BACKEND_REMOTE_SYNCHRONIZED_CACHE = '\Magento\Framework\Cache\Backend\RemoteSynchronizedCache ' ;
31
+ public const REDIS_BACKEND_CM_CACHE = 'Cm_Cache_Backend_Redis ' ;
32
+ public const REDIS_BACKEND_REDIS_CACHE = '\Magento\Framework\Cache\Backend\Redis ' ;
33
+ public const REDIS_BACKEND_REMOTE_SYNCHRONIZED_CACHE = '\Magento\Framework\Cache\Backend\RemoteSynchronizedCache ' ;
33
34
34
- const AVAILABLE_REDIS_BACKEND = [
35
+ public const AVAILABLE_REDIS_BACKEND = [
35
36
self ::REDIS_BACKEND_CM_CACHE ,
36
37
self ::REDIS_BACKEND_REDIS_CACHE ,
37
38
self ::REDIS_BACKEND_REMOTE_SYNCHRONIZED_CACHE
@@ -83,7 +84,7 @@ public function __construct(
83
84
* Returns an empty array in other case.
84
85
*
85
86
* @return array
86
- * @throws \Magento\MagentoCloud\Config\ ConfigException
87
+ * @throws ConfigException
87
88
*/
88
89
public function get (): array
89
90
{
@@ -162,7 +163,7 @@ public function get(): array
162
163
* @param array $envCacheConfiguration
163
164
* @param array $redisConfig
164
165
* @return array
165
- * @throws \Magento\MagentoCloud\Config\ ConfigException
166
+ * @throws ConfigException
166
167
*/
167
168
private function getSlaveConnection (array $ envCacheConfiguration , array $ redisConfig ): array
168
169
{
@@ -176,6 +177,11 @@ private function getSlaveConnection(array $envCacheConfiguration, array $redisCo
176
177
$ config ['load_from_slave ' ]['port ' ] = $ redisSlaveConfig ['port ' ] ?? '' ;
177
178
$ config ['read_timeout ' ] = 1 ;
178
179
$ config ['retry_reads_on_master ' ] = 1 ;
180
+
181
+ if (!empty ($ redisSlaveConfig ['password ' ])) {
182
+ $ config ['load_from_slave ' ]['password ' ] = $ redisSlaveConfig ['password ' ];
183
+ }
184
+
179
185
$ this ->logger ->info ('Set Redis slave connection ' );
180
186
} else {
181
187
$ this ->logger ->notice (
@@ -211,7 +217,7 @@ private function isCacheConfigurationValid(array $cacheConfiguration): bool
211
217
* @param array $envCacheConfig
212
218
* @param array $redisConfig
213
219
* @return bool
214
- * @throws \Magento\MagentoCloud\Config\ ConfigException
220
+ * @throws ConfigException
215
221
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
216
222
*/
217
223
private function isConfigurationCompatibleWithSlaveConnection (
@@ -253,13 +259,19 @@ private function isConfigurationCompatibleWithSlaveConnection(
253
259
*/
254
260
private function getUnsyncedConfigStructure (string $ envCacheBackendModel , array $ redisConfig ): array
255
261
{
256
- return [
262
+ $ config = [
257
263
'backend ' => $ envCacheBackendModel ,
258
264
'backend_options ' => [
259
265
'server ' => $ redisConfig ['host ' ],
260
266
'port ' => $ redisConfig ['port ' ],
261
267
]
262
268
];
269
+
270
+ if (!empty ($ redisConfig ['password ' ])) {
271
+ $ config ['backend_options ' ]['password ' ] = (string )$ redisConfig ['password ' ];
272
+ }
273
+
274
+ return $ config ;
263
275
}
264
276
265
277
/**
@@ -271,7 +283,7 @@ private function getUnsyncedConfigStructure(string $envCacheBackendModel, array
271
283
*/
272
284
private function getSynchronizedConfigStructure (string $ envCacheBackendModel , array $ redisConfig ): array
273
285
{
274
- return [
286
+ $ config = [
275
287
'backend ' => $ envCacheBackendModel ,
276
288
'backend_options ' => [
277
289
'remote_backend ' => '\Magento\Framework\Cache\Backend\Redis ' ,
@@ -292,17 +304,24 @@ private function getSynchronizedConfigStructure(string $envCacheBackendModel, ar
292
304
'write_control ' => false ,
293
305
]
294
306
];
307
+
308
+ if (!empty ($ redisConfig ['password ' ])) {
309
+ $ config ['backend_options ' ]['remote_backend_options ' ]['password ' ] = (string )$ redisConfig ['password ' ];
310
+ }
311
+
312
+ return $ config ;
295
313
}
296
314
297
315
/**
298
316
* Checks that config contains synchronized cache model and need to use synchronized config structure.
299
317
*
300
318
* @return bool
301
- * @throws \Magento\MagentoCloud\Config\ ConfigException
319
+ * @throws ConfigException
302
320
*/
303
321
private function isSynchronizedConfigStructure (): bool
304
322
{
305
323
$ model = (string )$ this ->stageConfig ->get (DeployInterface::VAR_CACHE_REDIS_BACKEND );
324
+
306
325
return $ model === self ::REDIS_BACKEND_REMOTE_SYNCHRONIZED_CACHE ;
307
326
}
308
327
}
0 commit comments