Name | quart-redis JSON |
Version |
3.0.0
JSON |
| download |
home_page | None |
Summary | A easy way of setting up a redis in quart |
upload_time | 2025-02-22 17:06:52 |
maintainer | None |
docs_url | None |
author | Leo Spratt |
requires_python | >=3.11 |
license | MIT |
keywords |
quart
asyncio
redis
cache
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Quart-Redis
[](https://quart-redis.readthedocs.io/en/latest/)






An easy way of setting up a redis connection in quart.
> View the docs [here](https://quart-redis.readthedocs.io/en/latest/).
## Requirements
- quart ~= 0.20
- redis >= 5.2.1, < 6
## Example
```python
# 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:
```python
# 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`](https://pypi.org/project/fakeredis/) package may be installed and then used instead of actual redis by setting `USE_FAKE_REDIS` environment variable to true at runtime.
Raw data
{
"_id": null,
"home_page": null,
"name": "quart-redis",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "quart, asyncio, redis, cache",
"author": "Leo Spratt",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/95/9f/065652204f581c446bdb368fd534b275efe2e79a4e118ee2d9c113dfe6b4/quart-redis-3.0.0.tar.gz",
"platform": null,
"description": "# Quart-Redis\n[](https://quart-redis.readthedocs.io/en/latest/)\n\n\n\n\n\n\n\nAn easy way of setting up a redis connection in quart.\n\n> View the docs [here](https://quart-redis.readthedocs.io/en/latest/).\n\n## Requirements\n- quart ~= 0.20\n- redis >= 5.2.1, < 6\n\n## Example\n\n```python\n# file: app.py\nfrom quart import Quart\nfrom quart_redis import RedisHandler, get_redis\n\napp = Quart(__name__)\napp.config[\"REDIS_URI\"] = \"redis://localhost\"\n# override default connection attempts, set < 0 to disable\n# app.config[\"REDIS_CONN_ATTEMPTS\"] = 3\nredis_handler = RedisHandler(app)\n\n@app.route(\"/\")\nasync def index():\n redis = get_redis()\n\n val = await redis.get(\"my-key\")\n\n if val is None:\n await redis.set(\"my-key\", \"it works!\")\n val = await redis.get(\"my-key\")\n\n return val\n```\n\n## Testing\nDue to quart_redis using `before_serving` and `after_serving`, using the Quart `test_client` requires the use of `test_app`. Pytest example shown below:\n\n```python\n# file: test.py\nimport pytest\nfrom app import app\n\n@pytest.fixture(name=\"my_app\", scope=\"function\")\nasync def _my_app():\n async with app.test_app() as test_app:\n yield test_app\n\nasync def test_redis(my_app):\n async with my_app.test_client() as client:\n result = await client.get(\"/\")\n assert result == b\"it works!\"\n```\n\n## Faking Redis\n\nFor development and testing, you may not have a running Redis instance. In this case, the [`fakeredis`](https://pypi.org/project/fakeredis/) package may be installed and then used instead of actual redis by setting `USE_FAKE_REDIS` environment variable to true at runtime.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A easy way of setting up a redis in quart",
"version": "3.0.0",
"project_urls": {
"changelog": "https://github.com/enchant97/quart-redis/blob/master/CHANGELOG.md",
"documentation": "https://quart-redis.readthedocs.io/en/stable/",
"homepage": "https://github.com/enchant97/quart-redis",
"repository": "https://github.com/enchant97/quart-redis.git"
},
"split_keywords": [
"quart",
" asyncio",
" redis",
" cache"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "beb80797dc45b917ed47618066ead68c08f7ad0a06375d99e54c89d7a0d43b3d",
"md5": "13982c939d35601aa9f2827f084f2f86",
"sha256": "78a9f16b80e7ca17189a09b022734796bf21a41a4d0c09f05c51acdabc27cd23"
},
"downloads": -1,
"filename": "quart_redis-3.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "13982c939d35601aa9f2827f084f2f86",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 4297,
"upload_time": "2025-02-22T17:06:51",
"upload_time_iso_8601": "2025-02-22T17:06:51.146965Z",
"url": "https://files.pythonhosted.org/packages/be/b8/0797dc45b917ed47618066ead68c08f7ad0a06375d99e54c89d7a0d43b3d/quart_redis-3.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "959f065652204f581c446bdb368fd534b275efe2e79a4e118ee2d9c113dfe6b4",
"md5": "b824a854be43256c1d22d39c73b34b45",
"sha256": "ec45d0535a6a6e0fd79b787173dd3cd51c7af5ab6d0bb285755e19bada56f8f9"
},
"downloads": -1,
"filename": "quart-redis-3.0.0.tar.gz",
"has_sig": false,
"md5_digest": "b824a854be43256c1d22d39c73b34b45",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 4193,
"upload_time": "2025-02-22T17:06:52",
"upload_time_iso_8601": "2025-02-22T17:06:52.965809Z",
"url": "https://files.pythonhosted.org/packages/95/9f/065652204f581c446bdb368fd534b275efe2e79a4e118ee2d9c113dfe6b4/quart-redis-3.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-22 17:06:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "enchant97",
"github_project": "quart-redis",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "quart-redis"
}