Skip to content

Commit 84c93bd

Browse files
committed
fix: redis test cases
1 parent 78f1a81 commit 84c93bd

6 files changed

Lines changed: 137 additions & 118 deletions

File tree

‎docs/DEVELOPMENT.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pre-commit helps maintain code quality by running checks before each commit.
3939

4040
1. Install pre-commit:
4141
```bash
42-
pip install pre-commit
42+
uv add --dev pre-commit
4343
```
4444

4545
2. Install the pre-commit hooks:

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dev = [
4747
"redis[hiredis]>=5.2.1",
4848
"ruff>=0.11.2",
4949
"tox>=4.25.0",
50+
"tox-uv>=1.29.0",
5051
"ty>=0.0.1a34",
5152
"types-orjson>=3.6.2",
5253
"types-redis>=4.6.0.20241004",

‎requirements.txt‎

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎tests/backends/test_redis.py‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ async def test_set_get(self, async_redis_backend: AsyncRedisCacheBackend):
117117
async def test_set_with_ttl(self, async_redis_backend: AsyncRedisCacheBackend):
118118
value = ETagContent(etag="test-etag", content=b"test-content")
119119
await async_redis_backend.set("test-key", value, ttl=100)
120-
ttl = await async_redis_backend.client.ttl("test-key")
120+
# Use _make_key to get the prefixed key
121+
ttl = await async_redis_backend.client.ttl(
122+
async_redis_backend._make_key("test-key")
123+
)
121124
assert ttl > 0 and ttl <= 100
122125

123126
@requires_redis
@@ -139,15 +142,18 @@ async def test_clear(self, async_redis_backend: AsyncRedisCacheBackend):
139142
@requires_redis
140143
async def test_clear_path(self, async_redis_backend: AsyncRedisCacheBackend):
141144
value = ETagContent(etag="test-etag", content=b"test-content")
142-
await async_redis_backend.set("/users/1", value)
143-
await async_redis_backend.set("/users/2", value)
144-
await async_redis_backend.set("/posts/1", value)
145-
146-
cleared = await async_redis_backend.clear_path("/users/", include_params=True)
145+
# Use proper cache key format: method:host:path:query_params
146+
# Keys without query params end with empty string after last colon
147+
await async_redis_backend.set("GET:localhost:/users/1:", value)
148+
await async_redis_backend.set("POST:localhost:/users/1:param=1", value)
149+
await async_redis_backend.set("GET:localhost:/posts/1:", value)
150+
151+
# Clear all /users/1 entries regardless of method/params
152+
cleared = await async_redis_backend.clear_path("/users/1", include_params=True)
147153
assert cleared == 2
148-
assert await async_redis_backend.get("/users/1") is None
149-
assert await async_redis_backend.get("/users/2") is None
150-
assert await async_redis_backend.get("/posts/1") == value
154+
assert await async_redis_backend.get("GET:localhost:/users/1:") is None
155+
assert await async_redis_backend.get("POST:localhost:/users/1:param=1") is None
156+
assert await async_redis_backend.get("GET:localhost:/posts/1:") == value
151157

152158
@requires_redis
153159
async def test_clear_pattern(self, async_redis_backend: AsyncRedisCacheBackend):

‎tox.ini‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ env_list =
88
py314
99

1010
[testenv]
11-
deps =
12-
pytest>=8.3.5
13-
pytest-asyncio>=0.26.0
14-
pytest-cov>=6.1.0
15-
coverage>=7.8.0
16-
httpx>=0.28.1
11+
runner = uv-venv-lock-runner
12+
extras =
13+
redis
14+
memcache
1715
commands = pytest {posargs:tests}
1816

1917
[gh-actions]

0 commit comments

Comments
 (0)