|
1 | 1 | from fastapi import APIRouter, Depends |
2 | 2 |
|
3 | | -from opa.utils.redis import get_aioredis, get_walrus |
4 | | -from opa.core.plugin import BasePlugin, get_component, get_redis, get_plugin_manager |
| 3 | +from opa.core.plugin import BasePlugin, get_component |
| 4 | +from opa.plugins.driver_redis import Walrus |
5 | 5 |
|
6 | 6 | router = APIRouter() |
7 | 7 |
|
8 | 8 |
|
9 | 9 | @router.get("/counter-async") |
10 | 10 | async def counter_async(aioredis=Depends(get_component('aioredis')), key=None): |
11 | | - key = key or 'incr-async' |
12 | | - counter = await aioredis.incr(key) |
| 11 | + counter = await aioredis.instance.incr(key or 'incr-async') |
13 | 12 | return f'Counter is {counter}' |
14 | 13 |
|
15 | 14 |
|
16 | 15 | @router.get("/counter-sync") |
17 | | -def counter_sync(walrus=Depends(get_component('walrus')), key=None): |
18 | | - key = key or 'incr-sync' |
19 | | - counter = walrus.incr(key) |
| 16 | +def counter_sync(walrus: Walrus = Depends(get_component('walrus')), key=None): |
| 17 | + counter = walrus.instance.incr(key or 'incr-sync') |
20 | 18 | return f'Counter is {counter}' |
21 | 19 |
|
22 | 20 |
|
23 | 21 | @router.get("/bloom") |
24 | 22 | def check_bloom_filter(string: str, walrus=Depends(get_component('walrus'))): |
25 | | - bf = walrus.bloom_filter('bf') |
| 23 | + bf = walrus.instance.bloom_filter('bf') |
26 | 24 | return string in bf |
27 | 25 |
|
28 | 26 |
|
29 | 27 | @router.post("/bloom") |
30 | 28 | def add_bloom_filter(string: str, walrus=Depends(get_component('walrus'))): |
31 | 29 | # Waiting for https://github.com/tiangolo/fastapi/issues/1018 to have plain/text input |
32 | 30 | # Possible now, but not with generation of the openapi spec.. |
33 | | - bf = walrus.bloom_filter('bf') |
| 31 | + bf = walrus.instance.bloom_filter('bf') |
34 | 32 | for i in string.split(' '): |
35 | 33 | bf.add(i) |
36 | 34 |
|
|
0 commit comments