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 hashes)

Uploaded Python 3

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