Skip to main content

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.

Source Distribution

redis-events-0.0.2.tar.gz (2.9 kB view details)

Uploaded Source

File details

Details for the file redis-events-0.0.2.tar.gz.

File metadata

  • Download URL: redis-events-0.0.2.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for redis-events-0.0.2.tar.gz
Algorithm Hash digest
SHA256 aa891b9d04f8034ee447bfd813006c201324f58016d1b807607a9a940b38a9e0
MD5 aab654e71ca3477d154b77f437fd81b8
BLAKE2b-256 3f1fe874af786543207ca0fc7ca1c4f8d7198b93fce353f152d95ab0a5639cb1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page