Skip to content

Conversation

finestructure
Copy link
Member

@finestructure finestructure commented Jan 5, 2025

This starts using Redis in place of the per node current reference cache for doc links.

I've ad hoc deployed this revision to dev and triggered the code path where it writes to Redis:

Screenshot 2025-01-05 at 11 00 03

I'll update the PR now to replace the in-memory cache.

Visit https://staging.swiftpackageindex.com/SwiftPackageIndex/SemanticVersion/~/documentation/semanticversion to hit the cache code path.

}

// This hostname has to match the redir service name in app.yml.
static let hostname = "redis"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make this configurable but there's not much point as it's not really dependent on anything, just a static name defined in app.yml.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only bit that I thought we might want to tweak and make into an environment variable, primarily so that a purely local development setup could reference LOCALHOST:6379 and had redis running in a container.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've simply set 127.0.0.1 redis in my /etc/hosts locally but of course making in configurable is better.

boundEventLoop: NIOSingletons.posixEventLoopGroup.any()
)
self.client = try await connection.get()
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give this whole actor Redis a thorough review, in particular how it's setting up the shared singleton with retries and the async throws initialiser that's using the @preconcurrency imported RedisConnection.

In particular, @preconcurrency is required, because RedisConnection isn't Sendable. I think this is correctly set up but good to have a proper review of this.

Unfortunately, there's not much I can see us do around this in terms of testing other than verifying that writing to and reading from Redis works on dev (which it does).

@finestructure finestructure marked this pull request as ready for review January 5, 2025 13:46
@Dependency(\.redis) var redis
await redis.set(key: getKey(owner: owner, repository: repository),
value: reference,
expiresIn: timeToLive)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heckj , this is how you'd interface with Redis once this lands. We wouldn't be using app.redis at all but rather the private Redis actor via the RedisClient dependency, replacing your PR #3580.

The only thing this doesn't cover is setup for local use of Redis, i.e. during development. It should be easy to add though, either by making the hostname configurable or just setting a redis alias in /etc/hosts on the local machine. The latter is certainly easiest and fastest to get going.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction, I just realised I misread your PR #3580. I was focused on the part

-        app.redis.configuration = try RedisConfiguration(hostname: "redis")
+        if let redisHost = Environment.get("REDIS_HOST") {
+            app.redis.configuration = try RedisConfiguration(hostname: redisHost)
+        } else {
+            app.logger.warning("REDIS_HOST not set, caching disabled.")
+        }

but really the point of it is to add a bringup for a local Redis and the hostname config.

@finestructure finestructure force-pushed the store-CurrentReferenceCache-in-redis branch from 6d59b58 to 1e40561 Compare January 6, 2025 08:25
@finestructure finestructure merged commit bdfff3e into main Jan 6, 2025
6 checks passed
@finestructure finestructure deleted the store-CurrentReferenceCache-in-redis branch January 6, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants