Skip to content

Conversation

@MistEO
Copy link
Contributor

@MistEO MistEO commented Jul 27, 2025

No description provided.

@MistEO MistEO requested review from Aliothmoon and Copilot July 27, 2025 13:52

This comment was marked as outdated.

@MistEO MistEO requested a review from Copilot July 27, 2025 13:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a Redis pub/sub system for cache invalidation and introduces Redis client functionality. The changes add the ability to subscribe to cache eviction messages and automatically clear both plan and contact caches when triggered.

  • Adds Redis client with pub/sub capabilities for cache management
  • Implements cache clearing functions for plan and contact data
  • Integrates cache subscriber into the FastAPI application lifecycle

Reviewed Changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/redis/subscriber.py Implements cache clearing subscriber that listens for eviction messages
src/redis/client.py Provides Redis client with connection, publish, and subscribe functionality
src/redis/init.py Exports Redis module components
src/plan/cache.py Adds cache clearing function for plan data
src/contact_us/init.py Adds cache clearing function and renames cache getter for consistency
src/config/init.py Adds Redis configuration settings
main.py Integrates Redis subscriber into application lifecycle and fixes import case

Comment on lines +28 to +29
if rds.pubsub:
await rds.pubsub.unsubscribe(channel)
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

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

The finally block checks rds.pubsub but should check pubsub (the local variable from line 12). This could cause the unsubscribe to not execute when rds.pubsub is None but pubsub exists.

Suggested change
if rds.pubsub:
await rds.pubsub.unsubscribe(channel)
if pubsub:
await pubsub.unsubscribe(channel)

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +29
if rds.pubsub:
await rds.pubsub.unsubscribe(channel)
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

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

This should use the local pubsub variable instead of rds.pubsub to ensure proper cleanup of the subscription created in this function.

Suggested change
if rds.pubsub:
await rds.pubsub.unsubscribe(channel)
if pubsub:
await pubsub.unsubscribe(channel)

Copilot uses AI. Check for mistakes.
logger.error("rds connect failed")
return

asyncio.create_task(cache_clear_subscriber())
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

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

The created task is not stored or awaited, which means there's no way to handle exceptions or ensure proper cleanup. Consider storing the task reference for better lifecycle management.

Suggested change
asyncio.create_task(cache_clear_subscriber())
task = asyncio.create_task(cache_clear_subscriber())
task.add_done_callback(lambda t: logger.error(f"Task cache_clear_subscriber failed: {t.exception()}") if t.exception() else logger.info("Task cache_clear_subscriber completed successfully"))

Copilot uses AI. Check for mistakes.

async for message in pubsub.listen():
if message["type"] == "message":
logger.info("evict message received: {}".format(message))
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Use f-string formatting instead of .format() for consistency with the rest of the codebase (as seen in lines 26 and 30).

Suggested change
logger.info("evict message received: {}".format(message))
logger.info(f"evict message received: {message}")

Copilot uses AI. Check for mistakes.
@MistEO MistEO closed this Jul 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants