Add get_stats to MemoryBackend and update pytest config
Added get_stats() method for consistency with RedisBackend. Also added httpx and pytest-asyncio as dev dependencies.
This commit is contained in:
@@ -134,6 +134,19 @@ class MemoryBackend(Backend):
|
|||||||
self._cleanup_task = None
|
self._cleanup_task = None
|
||||||
await self.clear()
|
await self.clear()
|
||||||
|
|
||||||
|
async def ping(self) -> bool:
|
||||||
|
"""Check if the backend is available. Always returns True for memory backend."""
|
||||||
|
return True
|
||||||
|
|
||||||
|
async def get_stats(self) -> dict[str, Any]:
|
||||||
|
"""Get statistics about the rate limit storage."""
|
||||||
|
async with self._lock:
|
||||||
|
return {
|
||||||
|
"total_keys": len(self._data),
|
||||||
|
"max_size": self._max_size,
|
||||||
|
"backend": "memory",
|
||||||
|
}
|
||||||
|
|
||||||
def __len__(self) -> int:
|
def __len__(self) -> int:
|
||||||
"""Return the number of stored entries."""
|
"""Return the number of stored entries."""
|
||||||
return len(self._data)
|
return len(self._data)
|
||||||
|
|||||||
@@ -94,12 +94,15 @@ reportMissingImports = false
|
|||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
asyncio_mode = "auto"
|
asyncio_mode = "auto"
|
||||||
|
asyncio_default_fixture_loop_scope = "function"
|
||||||
testpaths = ["tests"]
|
testpaths = ["tests"]
|
||||||
addopts = "-v --tb=short"
|
addopts = "-v --tb=short"
|
||||||
|
|
||||||
[dependency-groups]
|
[dependency-groups]
|
||||||
dev = [
|
dev = [
|
||||||
"fastapi>=0.128.0",
|
"fastapi>=0.128.0",
|
||||||
|
"httpx>=0.28.1",
|
||||||
"pytest>=9.0.2",
|
"pytest>=9.0.2",
|
||||||
|
"pytest-asyncio>=1.3.0",
|
||||||
"uvicorn>=0.40.0",
|
"uvicorn>=0.40.0",
|
||||||
]
|
]
|
||||||
|
|||||||
4
uv.lock
generated
4
uv.lock
generated
@@ -247,7 +247,9 @@ redis = [
|
|||||||
[package.dev-dependencies]
|
[package.dev-dependencies]
|
||||||
dev = [
|
dev = [
|
||||||
{ name = "fastapi" },
|
{ name = "fastapi" },
|
||||||
|
{ name = "httpx" },
|
||||||
{ name = "pytest" },
|
{ name = "pytest" },
|
||||||
|
{ name = "pytest-asyncio" },
|
||||||
{ name = "uvicorn" },
|
{ name = "uvicorn" },
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -273,7 +275,9 @@ provides-extras = ["redis", "fastapi", "all", "dev"]
|
|||||||
[package.metadata.requires-dev]
|
[package.metadata.requires-dev]
|
||||||
dev = [
|
dev = [
|
||||||
{ name = "fastapi", specifier = ">=0.128.0" },
|
{ name = "fastapi", specifier = ">=0.128.0" },
|
||||||
|
{ name = "httpx", specifier = ">=0.28.1" },
|
||||||
{ name = "pytest", specifier = ">=9.0.2" },
|
{ name = "pytest", specifier = ">=9.0.2" },
|
||||||
|
{ name = "pytest-asyncio", specifier = ">=1.3.0" },
|
||||||
{ name = "uvicorn", specifier = ">=0.40.0" },
|
{ name = "uvicorn", specifier = ">=0.40.0" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user