Skip to content

Commit 88d6de9

Browse files
author
Lars Solberg
committed
more bloomfilter example
1 parent 22bf054 commit 88d6de9

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

examples/docker-compose/redis/plugins/redisfun.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from fastapi import Request
12
from opa import get_instance, get_router
23

34
router = get_router()
@@ -23,12 +24,18 @@ def check_bloom_filter(string: str):
2324

2425

2526
@router.post("/bloom")
26-
def add_bloom_filter(string: str):
27+
async def add_bloom_filter(request: Request, string: str = None):
2728
# Waiting for https://github.com/tiangolo/fastapi/issues/1018 to have plain/text input
2829
# Possible now, but not with generation of the openapi spec..
2930
walrus = get_instance('walrus')
3031
bf = walrus.bloom_filter('bf')
31-
for i in string.split(' '):
32-
bf.add(i)
3332

34-
return f'Added entries'
33+
if string is None:
34+
async for chunk in request.stream():
35+
for i in chunk.split():
36+
bf.add(i)
37+
else:
38+
for i in string.split():
39+
bf.add(i)
40+
41+
return 'Added entries'

0 commit comments

Comments
 (0)