4.3. Redis
This plugin connects to the Redis database. It will return redis.Redis
connection
to the context.
In order to use it, you need to add these settings:
def redis(settings):
return {
"host": "redis",
"port": 6379,
"db": 0,
}
Second step is to add the plugin, like any other plugins:
class MyApplication(Application):
def create_plugins(self):
self.plugins[REDIS_PLUGIN_KEY] = RedisPlugin()
The ctx_key is ‘redis’ by default. Now you can use it in your application:
with Context(app) as ctx:
print(ctx[REDIS_PLUGIN_KEY])
assert type(ctx[REDIS_PLUGIN_KEY]) == redis.Redis