https://github.com/3jackdaws/redis-events
Event based distributed computing using Redis and asyncio
https://github.com/3jackdaws/redis-events
asyncio events python redis
Last synced: about 2 months ago
JSON representation
Event based distributed computing using Redis and asyncio
- Host: GitHub
- URL: https://github.com/3jackdaws/redis-events
- Owner: 3jackdaws
- Created: 2018-09-04T06:05:38.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-04T06:12:46.000Z (almost 8 years ago)
- Last Synced: 2026-01-05T11:53:37.479Z (6 months ago)
- Topics: asyncio, events, python, redis
- Language: Python
- Size: 3.91 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Redis Events
Event based distributed computing using Redis and asyncio
# Usage
Create a worker that will respond to events:
```py
# worker.py
from redis_events import Client, Event
# Point client at Redis server
client = Client(
host="mywebsite.com",
port=6379,
password="PASSWORD123"
)
@client.event("echo") # name the event whatever you want
async def echo_example(event: Event):
reply_event = Event(
"echo", # this doesn't actually matter because it is a reply
event.data # echo the data that was in the first event
)
await client.send_reply(event, reply_event)
client.run()
```
Create a script that will push events
```py
# send_events.py
from redis_events import Client
import asyncio
# obviously, must point to the same Redis server as the worker
client = Client(
host="mywebsite.com",
port=6379,
password="PASSWORD123"
)
# Everything is async
async def send_events():
my_event = Event(
"echo",
{"test": 1234}
)
await client.send(my_event)
reply = await client.wait_for_reply(to=my_event, timeout=60) # wait for a reply for up to 1 minute
print("GOT REPLY")
asyncio.get_event_loop().run_until_complete(send_events())
```
# Installation
`pip install redis-events`