Skip to main content

Async-native Redis-backed RPC and job queue

Project description

Raddish

Raddish is mix of RPC and job queue backed by Redis. You can launch multiple servers that will accept the same function calls in a round-robin fashion. From the client side you can asynchronously submit jobs and block the execution until they are completed.


Getting started

  1. Implement a server
import asyncio
import logging
import os

from redis.asyncio import Redis
from rich.logging import RichHandler

from raddish import RaddishServer, AsyncWorker

logging.basicConfig(
    level=logging.INFO,
    format="%(message)s",
    datefmt="[%X]",
    handlers=[RichHandler(rich_tracebacks=True)],
)

logger = logging.getLogger("raddish-test")


class TestWorker(AsyncWorker):
    async def setup(self) -> None:
        logger.info("Setting up test worker")

    async def __call__(self, input: dict[str, any]) -> dict[str, any]:
        logger.info(f"Received input: {input}")
        input: int = input["number"]
        input += 1
        await asyncio.sleep(10)
        return {
            "number": input,
        }


async def main() -> None:
    redis_client: Redis = Redis.from_url(
        os.environ.get("REDIS_URL", "redis://localhost:6379")
    )
    server: RaddishServer = RaddishServer(redis_client)
    server.add_worker("add_one", TestWorker())
    await server.start()


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
  1. Implement a client
import asyncio
import logging
import os

from redis.asyncio import Redis
from rich.logging import RichHandler

from raddish import AsyncRaddishClient

logging.basicConfig(
    level=logging.INFO,
    format="%(message)s",
    datefmt="[%X]",
    handlers=[RichHandler(rich_tracebacks=True)],
)

logger = logging.getLogger("raddish-test")


async def main() -> None:
    redis_client: Redis = Redis.from_url(
        os.environ.get("REDIS_URL", "redis://localhost:6379")
    )
    client: AsyncRaddishClient = AsyncRaddishClient(redis_client)

    counter: int = 0
    for _ in range(5):
        logger.info(f"Sending input {counter}")
        counter = (await client.call("add_one", {"number": counter}))["number"]
        logger.info(f"Received output {counter}")


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
  1. Launch one or more servers
python server.py
  1. Launch one or more clients
python client.py

Features

  • You can add servers at any time in order to increase capacity
  • Asyncio-native
  • Servers can be located anywhere where there is internet, no need to have public ip - you only need to be able to connect to the redis server

License

Raddish is licensed under Apache License, Version 2.0

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

raddish-0.2.4.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

raddish-0.2.4-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file raddish-0.2.4.tar.gz.

File metadata

  • Download URL: raddish-0.2.4.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for raddish-0.2.4.tar.gz
Algorithm Hash digest
SHA256 91785bc752f2b511f2861e238ddd395fb638e48201737601d9d5b912584d860d
MD5 796619051024fe41080053db23bb1363
BLAKE2b-256 3b7888d415ad48da2d79d522ce78f4b24662627f6032e8802e88ef2813efd28f

See more details on using hashes here.

File details

Details for the file raddish-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: raddish-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for raddish-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 89eb14e4cf7dfff15a9f802407c765e3c283602b3d216472e83b417408baca71
MD5 9260b5703ce1c4b0ba9dc0f6862c9e92
BLAKE2b-256 03b3495dade5e68e09e446e96693a80f38ee22a6f21a361748746b89901a676f

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