Charmed Redis K8s

Channel Revision Published Runs on
latest/stable 7 12 May 2021
Ubuntu 20.04
latest/edge 27 04 Dec 2023
Ubuntu 22.04
juju deploy redis-k8s
Show information

Platform:

charms.redis_k8s.v0.redis

Library for the redis relation.

This library contains the Requires and Provides classes for handling the redis interface.

Import RedisRequires in your charm by adding the following to src/charm.py:

from charms.redis_k8s.v0.redis import RedisRequires

Define the following attributes in charm charm class for the library to be able to work with it

 _stored = StoredState()
    on = RedisRelationCharmEvents()

And then in your charm's __init__ method:

# Make sure you set redis_relation in StoredState. Assuming you refer to this
# as `self._stored`:
self._stored.set_default(redis_relation={})
self.redis = RedisRequires(self, self._stored)

And then wherever you need to reference the relation data it will be available in the property relation_data:

redis_host = self.redis.relation_data.get("hostname")
redis_port = self.redis.relation_data.get("port")

You will also need to add the following to metadata.yaml:

requires:
  redis:
    interface: redis

class RedisRelationUpdatedEvent

Description

An event for the redis relation having been updated. None

class RedisRelationCharmEvents

Description

A class to carry custom charm events so requires can react to relation changes. None

class RedisRequires

Methods

RedisRequires. __init__( self , charm , _stored , relation_name: str )

Description

A class implementing the redis requires relation. None

RedisRequires. relation_data( self )

Retrieve the relation data.

Returns

Dict

dict containing the relation data.

RedisRequires. url( self )

Retrieve the Redis URL.

Returns

str

the Redis URL.

class RedisProvides

Methods

RedisProvides. __init__( self , charm , port )

Description

A class implementing the redis provides relation. None