-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdependency.py
More file actions
46 lines (34 loc) · 1.19 KB
/
Copy pathdependency.py
File metadata and controls
46 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Dependency injection for Redis client in Nexios.
This module provides dependency injection utilities for accessing
Redis client and performing Redis operations in route handlers.
"""
from __future__ import annotations
from typing import cast
from nexios.dependencies import Depend
from . import get_redis
from .client import RedisClient
def RedisDepend() -> RedisClient:
"""
Dependency injection function for accessing Redis client.
This function can be used as a dependency in route handlers to
automatically inject the Redis client instance.
Returns:
RedisClient: Dependency injection wrapper function.
Example:
```python
from nexios import NexiosApp
from nexios_contrib.redis import RedisDepend
app = NexiosApp()
@app.get("/cache/{key}")
async def get_cached_data(
request: Request,
response: Response,
redis: RedisClient = RedisDepend() # Injects RedisClient
):
# Use redis client directly
value = await redis.get(request.path_params["key"])
return {"value": value}
```
"""
return cast(RedisClient, Depend(get_redis))