Skip to main content

A easy way of setting up a redis in quart

Project description

Quart-Redis

Documentation Status PyPI PyPI - Python Version PyPI - Downloads GitHub GitHub issues GitHub last commit

An easy way of setting up a redis connection in quart.

View the docs here.

Requirements

  • quart ~= 0.20
  • redis >= 5.2.1, < 6

Example

# file: app.py
from quart import Quart
from quart_redis import RedisHandler, get_redis

app = Quart(__name__)
app.config["REDIS_URI"] = "redis://localhost"
# override default connection attempts, set < 0 to disable
# app.config["REDIS_CONN_ATTEMPTS"] = 3
redis_handler = RedisHandler(app)

@app.route("/")
async def index():
    redis = get_redis()

    val = await redis.get("my-key")

    if val is None:
        await redis.set("my-key", "it works!")
        val = await redis.get("my-key")

    return val

Testing

Due to quart_redis using before_serving and after_serving, using the Quart test_client requires the use of test_app. Pytest example shown below:

# file: test.py
import pytest
from app import app

@pytest.fixture(name="my_app", scope="function")
async def _my_app():
    async with app.test_app() as test_app:
        yield test_app

async def test_redis(my_app):
    async with my_app.test_client() as client:
        result = await client.get("/")
        assert result == b"it works!"

Faking Redis

For development and testing, you may not have a running Redis instance. In this case, the fakeredis package may be installed and then used instead of actual redis by setting USE_FAKE_REDIS environment variable to true at runtime.

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

quart-redis-3.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quart_redis-3.0.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file quart-redis-3.0.0.tar.gz.

File metadata

  • Download URL: quart-redis-3.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for quart-redis-3.0.0.tar.gz
Algorithm Hash digest
SHA256 ec45d0535a6a6e0fd79b787173dd3cd51c7af5ab6d0bb285755e19bada56f8f9
MD5 b824a854be43256c1d22d39c73b34b45
BLAKE2b-256 959f065652204f581c446bdb368fd534b275efe2e79a4e118ee2d9c113dfe6b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for quart-redis-3.0.0.tar.gz:

Publisher: python-publish.yml on enchant97/quart-redis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quart_redis-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: quart_redis-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for quart_redis-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78a9f16b80e7ca17189a09b022734796bf21a41a4d0c09f05c51acdabc27cd23
MD5 13982c939d35601aa9f2827f084f2f86
BLAKE2b-256 beb80797dc45b917ed47618066ead68c08f7ad0a06375d99e54c89d7a0d43b3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for quart_redis-3.0.0-py3-none-any.whl:

Publisher: python-publish.yml on enchant97/quart-redis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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