8 Commits

Author SHA1 Message Date
Sander 53a82fda3f Bump version 2022-03-10 15:00:32 +02:00
Sander a82799d358 use self._config instead of app.config 2022-03-10 14:59:32 +02:00
Sander 80f39ec79b Merge pull request #8 from sanderfoobar/session-uri-docs
Change README to support new config option `SESSION_URI`
2022-03-10 14:55:03 +02:00
Sander 9d02429aee Change README to support new config option SESSION_URI 2022-03-10 14:54:41 +02:00
Sander 13fcc653c6 Merge pull request #7 from rubikscuber/patch-1
respect custom redis uri
2022-03-10 14:52:40 +02:00
rubikscuber 16fb57d62a add SESSION_URI example 2022-03-10 13:51:13 +01:00
rubikscuber 43956f045f Update sessions.py 2022-03-10 13:45:28 +01:00
rubikscuber cdd237b5f9 respect custom redis uri
enable usage of app.config["REDIS_URI"]
2022-03-10 11:28:03 +01:00
4 changed files with 32 additions and 16 deletions
+26 -12
View File
@@ -16,7 +16,7 @@ $ pipenv install quart-session
$ pip install quart-session
```
and requires Python 3.7.0 or higher. A fairly minimal Quart-Session example is,
and requires Python 3.7.0 or higher. A minimal Quart-Session example is:
```python3
from quart import Quart, session
@@ -29,7 +29,11 @@ Session(app)
@app.route('/')
async def hello():
session["foo"] = "bar"
return 'hello'
return "session key 'foo' set"
@app.route('/foo')
async def foo():
return session.get("foo", "session key 'foo' not found")
app.run()
```
@@ -37,9 +41,9 @@ app.run()
## Features
### Redis support
### Redis
via `aioredis`.
via `aioredis>=2.0.0`.
```python3
app = Quart(__name__)
@@ -47,8 +51,16 @@ app.config['SESSION_TYPE'] = 'redis'
Session(app)
```
If you already have a `aioredis.Client` instance and you'd like to share
it with the session interface,
By default, Quart-session connects to Redis at `127.0.0.1:6379`. If you
have a different location, use `SESSION_URI`
```python3
app = Quart(__name__)
app.config['SESSION_TYPE'] = 'redis'
app.config['SESSION_URI'] = 'redis://:password@localhost:6379'
```
Alternatively, for extra control, you may provide your own `aioredis.Client` instance altogether.
```python3
app = Quart(__name__)
@@ -56,15 +68,17 @@ app.config['SESSION_TYPE'] = 'redis'
@app.before_serving
async def setup():
cache = await aioredis.create_redis_pool(...)
cache = await aioredis.Redis(
host="foobar.com",
port=6379,
password="foobar"
)
app.config['SESSION_REDIS'] = cache
Session(app)
```
By default, Quart-session creates a single connection to Redis, while
the example above sets up a connection pool.
#### Trio support
#### Trio
Quart-Session comes with [an (experimental) Redis client](quart_session/redis_trio) for use with the [Trio](https://trio.readthedocs.io/en/stable/) eventloop.
@@ -77,7 +91,7 @@ app.config['SESSION_TYPE'] = 'redis'
Session(app)
```
### Memcached support
### Memcached
via `aiomcache`.
+1 -1
View File
@@ -10,7 +10,7 @@
:license: BSD, see LICENSE for more details.
"""
__version__ = '1.0.3'
__version__ = '1.0.4'
import os
+4 -2
View File
@@ -224,12 +224,14 @@ class RedisSessionInterface(SessionInterface):
.. note::
Creates a single Redis connection, you might prefer
pooling instead (see ``aioredis.Redis.create_redis_pool``)
pooling instead (see the `aioredis` documentation
for connection pool examples).
"""
if self.backend is None:
import aioredis
uri = self._config.get('SESSION_URI', 'redis://localhost')
self.backend = await aioredis.from_url(
"redis://localhost", encoding="utf-8", decode_responses=True
uri, encoding="utf-8", decode_responses=True
)
async def get(self, key: str, app: Quart = None):
+1 -1
View File
@@ -24,7 +24,7 @@ INSTALL_REQUIRES = [
setup(
name='Quart-Session',
version='1.0.3',
version='1.0.4',
url='https://github.com/sferdi0/quart-session',
license='BSD',
author='Sander',