-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestproduceraio.py
More file actions
31 lines (24 loc) · 1.18 KB
/
testproduceraio.py
File metadata and controls
31 lines (24 loc) · 1.18 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
from pyredishelper.proxy import RedisProxy
from pyredishelper.protocols import AioProducerProtocol, AioStreamProducerProtocol
from pyredishelper.queueproducer import QueueProducerHelper
from pyredishelper.channelproducer import ChannelProducerHelper
from pyredishelper.streamproducer import StreamProducerHelper
from typing import cast
import asyncio
rediscli = RedisProxy()
async def runcode() -> None:
# qp = cast(AioProducerProtocol, QueueProducerHelper.from_proxy(rediscli))
# qp = cast(AioProducerProtocol, ChannelProducerHelper.from_proxy(rediscli))
qp = cast(AioStreamProducerProtocol, StreamProducerHelper.from_proxy(rediscli, maxlen=20))
async with qp.mount() as producer:
for i in range(10):
topicnum = i % 3 + 1
# await producer.publish(f"topic{topicnum}", f"test {i}"})
await producer.publish(f"topic{topicnum}", {"key": "a key", "value": f"{i}y"})
print(f"send test{i} to topic{topicnum}")
await asyncio.sleep(0.1)
async def main() -> None:
rediscli.initialize_from_url("redis+async://localhost:6379/0?decode_responses=true")
await runcode()
if __name__ == "__main__":
asyncio.run(main())