22
33namespace craft \cloud ;
44
5+ use Closure ;
56use Craft ;
67use craft \cache \DbCache ;
78use craft \cloud \fs \TmpFs ;
@@ -47,7 +48,7 @@ public function getConfig(): array
4748 return $ config ;
4849 }
4950
50- private function getSession (): \ Closure
51+ private function getSession (): Closure
5152 {
5253 return function () {
5354 $ config = App::sessionConfig ();
@@ -61,39 +62,20 @@ private function getSession(): \Closure
6162 };
6263 }
6364
64- private function getCache (): \ Closure
65+ private function getCache (): Closure
6566 {
6667 return function () {
6768 $ defaultDuration = Craft::$ app ->getConfig ()->getGeneral ()->cacheDuration ;
6869
69- $ redisSrv = App::env ('CRAFT_CLOUD_REDIS_SRV ' );
70-
71- // Temporary for testing it out
72- if ($ redisSrv ) {
73- $ record = dns_get_record ($ redisSrv , DNS_SRV );
74-
75- $ url = 'redis:// ' . $ record [0 ]['target ' ] . ': ' . $ record [0 ]['port ' ];
70+ $ valkey = $ this ->resolveValkeyEndpoint ();
7671
72+ if ($ valkey ) {
7773 return Craft::createObject ([
7874 'class ' => Cache::class,
7975 'defaultDuration ' => $ defaultDuration ,
8076 'redis ' => [
8177 'class ' => Redis::class,
82- 'url ' => $ url ,
83- 'database ' => 0 ,
84- ],
85- ]);
86- }
87-
88- $ redisUrl = App::env ('CRAFT_CLOUD_REDIS_URL ' );
89-
90- if ($ redisUrl ) {
91- return Craft::createObject ([
92- 'class ' => Cache::class,
93- 'defaultDuration ' => $ defaultDuration ,
94- 'redis ' => [
95- 'class ' => Redis::class,
96- 'url ' => $ redisUrl ,
78+ 'url ' => $ valkey ,
9779 'database ' => 0 ,
9880 ],
9981 ]);
@@ -111,7 +93,24 @@ private function getCache(): \Closure
11193 };
11294 }
11395
114- private function getQueue (): \Closure
96+ private function resolveValkeyEndpoint (): string
97+ {
98+ $ srv = App::env ('CRAFT_CLOUD_CACHE_SRV ' );
99+
100+ if ($ srv ) {
101+ $ record = dns_get_record ($ srv , DNS_SRV );
102+
103+ if (! empty ($ record )) {
104+ return 'redis:// ' . $ record [0 ]['target ' ] . ': ' . $ record [0 ]['port ' ];
105+ }
106+ }
107+
108+ // Deprecated. We are moving to CRAFT_CLOUD_CACHE_SRV for both Fargate and ECS.
109+ // Once every website is moved over, we can disregared this fallback.
110+ return App::env ('CRAFT_CLOUD_REDIS_URL ' );
111+ }
112+
113+ private function getQueue (): Closure
115114 {
116115 return function () {
117116 return Craft::createObject ([
@@ -127,7 +126,7 @@ private function getQueue(): \Closure
127126 };
128127 }
129128
130- private function getAssetManager (): \ Closure
129+ private function getAssetManager (): Closure
131130 {
132131 return function () {
133132 $ config = [
0 commit comments