Skip to main content

sanic redis extend

Project description

sanic-redis

Redis support for sanic.

Built on top of aioredis.

Installation

You can install this package as usual with pip:

pip install sanic-redis-extend

Config

For example:

redis://[[username]:[password]]@localhost:6379/0
rediss://[[username]:[password]]@localhost:6379/0
unix://[[username]:[password]]@/path/to/socket.sock?db=0

Example

from sanic import Sanic
from sanic.response import text
from sanic_redis_extend import SanicRedisExtend

app = Sanic(__name__)

app.config.update(
    {
        'REDIS': "redis://default:xxx@127.0.0.1:6379/1",
    }
)

redis = SanicRedisExtend()
redis.init_app(app)


@app.route('/')
async def test3(request):
    # request.app.ctx.{redis_name}, the {redis_name} == config_name.lower()
    async with request.app.ctx.redis as r:
        await r.set('key1', 'value1')
        result = await r.get('key1')
    return text(str(result))


if __name__ == '__main__':
    app.run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

sanic_redis_extend-0.0.1-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file sanic_redis_extend-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sanic_redis_extend-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 981d6f30eb8d2ee7e6bbf5893bb95ea675456a3a9d7fe3b51bbeb97b14bde1ea
MD5 e1af0e9e917d9d4d7b95206a83a54672
BLAKE2b-256 8829ac1b04ba7ddfb209af9a68ab7020128312539b00c62b5582388ba5225b3a

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