Skip to content

Commit 01c591b

Browse files
committed
(refactor): drop redundant cache layer and cross-process test for redis adapter
1 parent b381931 commit 01c591b

6 files changed

Lines changed: 25 additions & 546 deletions

File tree

.github/workflows/tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ jobs:
8080
Mirror,
8181
Pool,
8282
Redis,
83-
RedisCrossProcess,
8483
SharedTables/MongoDB,
8584
SharedTables/MariaDB,
8685
SharedTables/MySQL,

src/Database/Adapter/Redis/Contract.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,8 @@ inverse operations through `rawDeleteDoc()` and `rawRestoreDoc()`.
179179
Relationship support is split across waves: T1 (this PR) lands the helper
180180
contract; T2 implements `createRelationship` / `updateRelationship` /
181181
`deleteRelationship`; T3 wires read-path null surfacing into every decoded
182-
document path; T4 flips the capability bit and adds a cross-process smoke
183-
test. The rules below are the locked contract — Wave-2 architects MUST NOT
184-
deviate.
182+
document path; T4 flips the capability bit. The rules below are the
183+
locked contract — Wave-2 architects MUST NOT deviate.
185184

186185
1. **Storage policy.** Relationship attributes ride on the existing
187186
`meta:{col}` HASH's `attrs` JSON field. The adapter writes a MINIMAL
@@ -247,8 +246,8 @@ deviate.
247246
| `private function loadMetadataDocument(string $collection): ?Document` | T1 |
248247

249248
7. **Capability bit.** `getSupportForRelationships()` returns `true`
250-
T2 (schema ops), T3 (read-path null surfacing), and T4 (capability flip
251-
+ cross-process smoke) have all shipped.
249+
T2 (schema ops), T3 (read-path null surfacing), and T4 (capability flip)
250+
have all shipped.
252251

253252
## Known limitations
254253

tests/e2e/Adapter/RedisBase.php

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Tests\E2E\Adapter;
44

55
use Redis;
6-
use Utopia\Cache\Adapter\Redis as RedisCacheAdapter;
6+
use Utopia\Cache\Adapter\None as NoneCacheAdapter;
77
use Utopia\Cache\Cache;
88
use Utopia\Database\Adapter\Redis as RedisAdapter;
99
use 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

Comments
 (0)