Skip to content

Add Redis storage#9

Merged
Nottezz merged 24 commits intomainfrom
feature/redis-storage
Jul 6, 2025
Merged

Add Redis storage#9
Nottezz merged 24 commits intomainfrom
feature/redis-storage

Conversation

@Nottezz
Copy link
Collaborator

@Nottezz Nottezz commented Jul 1, 2025

No description provided.

@Nottezz Nottezz requested a review from chud0 July 1, 2025 14:25
@Nottezz Nottezz self-assigned this Jul 1, 2025
@Nottezz Nottezz linked an issue Jul 1, 2025 that may be closed by this pull request
@chud0
Copy link
Owner

chud0 commented Jul 2, 2025

bugbot run

@cursor
Copy link

cursor bot commented Jul 2, 2025

🚨 BugBot couldn't run

Something went wrong. Try again by commenting "bugbot run", or contact support (requestId: serverGenReqId_1147f7b6-5514-4a42-b008-379cb0360d64).

Nottezz added 2 commits July 2, 2025 09:08
# Conflicts:
#	fast_cache_middleware/serializers.py
#	fast_cache_middleware/storages/in_memory_storage.py
#	poetry.lock
#	pyproject.toml
@chud0
Copy link
Owner

chud0 commented Jul 2, 2025

bugbot run verbose=true

@cursor
Copy link

cursor bot commented Jul 2, 2025

BugBot request id: serverGenReqId_e8655b00-8a95-4772-9da2-6152f962ed95

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Middleware Initialization Error

The FastCacheMiddleware is incorrectly initialized with a raw Redis client (storage=redis) instead of a RedisStorage instance. The middleware expects an object implementing the BaseStorage interface, which the raw Redis client does not provide, leading to runtime errors. The correct initialization should be storage=RedisStorage(redis).

examples/redis_example.py#L26-L27

# Добавляем middleware - он проанализирует роуты при первом запросе
app.add_middleware(FastCacheMiddleware, storage=redis)

Fix in Cursor


Bug: Redis Key Removal Fails with Regex and Incomplete Scans

The RedisStorage.remove method has two issues: It incorrectly converts regex patterns (e.g., .*) to Redis glob patterns (e.g., ./* instead of *), preventing intended keys from being matched. Additionally, it only performs a single Redis SCAN operation, failing to iterate through all results using the cursor, which leads to incomplete cache invalidation for large datasets.

fast_cache_middleware/storages/redis_storage.py#L85-L107

async def remove(self, path: re.Pattern) -> None:
"""
Deleting the cache using the specified path
"""
raw = path.pattern
if raw.startswith("^"):
raw = raw[1:]
pattern = self._full_key(str(raw.rstrip("$") + "/*"))
logger.debug(f"Removing key: %s", pattern)
result = await self._storage.scan(match=pattern)
if not result[1]:
logger.warning("The search did not find any matches")
return
logger.debug(f"Result: %s", result[1])
for value in result[1]:
await self._storage.delete(value)
logger.info(f"Key deleted from Redis: %s", value)

Fix in Cursor


BugBot free trial expires on July 22, 2025
You have used $0.00 of your $5.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

@Nottezz Nottezz requested a review from chud0 July 4, 2025 10:14
2. Extracting configuration cache from dependencies;
3. Automatic caching of GET requests in Redis;
4. Cache invalidation in case of modifying requests.
"""
Copy link
Owner

Choose a reason for hiding this comment

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

можно дописать как ставить с екстрой, чтобы редис поставился

@Nottezz Nottezz merged commit 24ce973 into main Jul 6, 2025
3 checks passed
@Nottezz Nottezz deleted the feature/redis-storage branch July 7, 2025 09:54
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.

Add new storage - Redis

2 participants

Comments