Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Event based distributed computing using Redis and asyncio

Project description

Redis Events

Event based distributed computing using Redis and asyncio

Usage

Create a worker that will respond to events:

# 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

# 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for redis-events, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size redis-events-0.0.2.tar.gz (2.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page