33namespace Tests \E2E \Adapter ;
44
55use Redis ;
6- use Utopia \Cache \Adapter \Redis as RedisCacheAdapter ;
6+ use Utopia \Cache \Adapter \None as NoneCacheAdapter ;
77use Utopia \Cache \Cache ;
88use Utopia \Database \Adapter \Redis as RedisAdapter ;
99use Utopia \Database \Database ;
@@ -21,9 +21,8 @@ abstract class RedisBase extends Base
2121 public static ?Database $ database = null ;
2222 public static ?Redis $ redisClient = null ;
2323 public static string $ redisNamespace = '' ;
24- public static ?Redis $ cacheRedisClient = null ;
25- /** @var array<int, string> Glob patterns the run owns, scrubbed in tearDownAfterClass. */
26- protected static array $ cacheKeyPatterns = [];
24+ /** @var array<int, string> Adapter-keyspace SCAN patterns the run owns, scrubbed in tearDownAfterClass. */
25+ protected static array $ keyPatterns = [];
2726
2827 public static function getAdapterName (): string
2928 {
@@ -58,15 +57,11 @@ public function getDatabase(): Database
5857 $ client ->connect ($ host , $ port );
5958 self ::$ redisClient = $ client ;
6059
61- $ cacheHost = \getenv ('CACHE_REDIS_HOST ' ) ?: 'redis ' ;
62- $ cachePort = (int ) (\getenv ('CACHE_REDIS_PORT ' ) ?: 6379 );
63- $ cacheRedis = new Redis ();
64- $ cacheRedis ->connect ($ cacheHost , $ cachePort );
65- self ::$ cacheRedisClient = $ cacheRedis ;
66- // Contract.md forbids FLUSHALL/FLUSHDB — the runner shares the
67- // cache instance across workers. Cache keys are scrubbed at
68- // tearDownAfterClass via the namespace-scoped scan below.
69- $ cache = new Cache (new RedisCacheAdapter ($ cacheRedis ));
60+ // Redis-as-adapter makes the Cache layer redundant — adapter reads
61+ // and cache reads cost the same Redis round trip, and any
62+ // invalidation gap between them just becomes a stale-read window.
63+ // None() short-circuits the cache so reads always hit Redis.
64+ $ cache = new Cache (new NoneCacheAdapter ());
7065
7166 $ adapter = new RedisAdapter ($ client );
7267
@@ -79,12 +74,12 @@ public function getDatabase(): Database
7974
8075 $ this ->configureDatabase ($ database );
8176
82- // Track every key pattern this run owns so tearDownAfterClass can
83- // scrub both the adapter's keyspace and the cache's keys without
84- // a global FLUSH. The configureDatabase() call above may have
85- // mutated the namespace (shared-tables uses ''), so capture the
86- // post-configure namespace too.
87- self ::$ cacheKeyPatterns = self ::buildKeyPatterns (self ::$ redisNamespace , $ database ->getNamespace (), $ database ->getDatabase ());
77+ // Track every adapter-keyspace pattern this run owns so
78+ // tearDownAfterClass can scrub without a global FLUSH. The
79+ // configureDatabase() call above may have mutated the namespace
80+ // (shared-tables uses ''), so capture the post-configure namespace
81+ // too.
82+ self ::$ keyPatterns = self ::buildKeyPatterns (self ::$ redisNamespace , $ database ->getNamespace (), $ database ->getDatabase ());
8883
8984 if ($ database ->exists ()) {
9085 $ database ->delete ();
@@ -96,10 +91,10 @@ public function getDatabase(): Database
9691 }
9792
9893 /**
99- * Build SCAN MATCH patterns covering both the adapter keyspace and the
100- * cache keyspace for the namespaces this test class actually wrote to.
101- * The two-namespace form (initial + post-configure) covers the
102- * shared-tables case where setNamespace('') is applied before create().
94+ * Build SCAN MATCH patterns covering the adapter keyspace for every
95+ * namespace this test class actually wrote to. The two-namespace form
96+ * (initial + post-configure) covers the shared-tables case where
97+ * setNamespace('') is applied before create().
10398 *
10499 * @return array<int, string>
105100 */
@@ -112,9 +107,6 @@ protected static function buildKeyPatterns(string $initialNamespace, string $eff
112107 // namespace produces a literal double-colon, which is a valid
113108 // SCAN pattern.
114109 $ patterns [] = RedisAdapter::KEY_PREFIX . ': ' . $ namespace . ': ' . $ database . ':* ' ;
115- // Cache writes go through Utopia\Cache\Adapter\Redis which
116- // composes its own keys; scope by namespace+database too.
117- $ patterns [] = $ namespace . ': ' . $ database . ':* ' ;
118110 }
119111 return \array_values (\array_unique ($ patterns ));
120112 }
@@ -156,18 +148,14 @@ public function testUpdateAttributeSize(): void
156148 public static function tearDownAfterClass (): void
157149 {
158150 try {
159- if (self ::$ cacheKeyPatterns !== [] && self ::$ redisClient instanceof Redis) {
160- self ::scrubKeys (self ::$ redisClient , self ::$ cacheKeyPatterns );
161- }
162- if (self ::$ cacheKeyPatterns !== [] && self ::$ cacheRedisClient instanceof Redis) {
163- self ::scrubKeys (self ::$ cacheRedisClient , self ::$ cacheKeyPatterns );
151+ if (self ::$ keyPatterns !== [] && self ::$ redisClient instanceof Redis) {
152+ self ::scrubKeys (self ::$ redisClient , self ::$ keyPatterns );
164153 }
165154 } finally {
166155 self ::$ database = null ;
167156 self ::$ redisClient = null ;
168- self ::$ cacheRedisClient = null ;
169157 self ::$ redisNamespace = '' ;
170- self ::$ cacheKeyPatterns = [];
158+ self ::$ keyPatterns = [];
171159 parent ::tearDownAfterClass ();
172160 }
173161 }
0 commit comments