Redis Parser

class django_docker_helpers.config.backends.redis_parser.RedisParser(endpoint='service', host='127.0.0.1', port=6379, db=0, path_separator='.', inner_parser_class=<class 'django_docker_helpers.config.backends.yaml_parser.YamlParser'>, **redis_options)[source]

Reads a whole config bundle from a redis key and provides the unified interface to access config options.

It assumes that config in your storage can be parsed with any simple parser, like YamlParser.

Compared to, e.g. EnvironmentParser it does not have scope support by design, since endpoint is a good enough scope by itself.

Example:

parser = RedisParser('my/server/config.yml', host=REDIS_HOST, port=REDIS_PORT)
parser.get('nested.a.b', coerce_type=int)
Parameters
  • endpoint (str) – specifies a redis key with serialized config, e.g. 'services/mailer/config.yml'

  • host (str) – redis host, default is '127.0.0.1'

  • port (int) – redis port, default id 6379

  • db (int) – redis database, default is 0

  • path_separator (str) – specifies which character separates nested variables, default is '.'

  • inner_parser_class (Optional[Type[BaseParser]]) – use the specified parser to read config from endpoint key

  • redis_options – additional options for redis.Redis client

get(variable_path, default=None, coerce_type=None, coercer=None, **kwargs)[source]

Reads a value of variable_path from redis storage.

Parameters
  • variable_path (str) – a delimiter-separated path to a nested value

  • default (Optional[Any]) – default value if there’s no object by specified path

  • coerce_type (Optional[Type]) – cast a type of a value to a specified one

  • coercer (Optional[Callable]) – perform a type casting with specified callback

  • kwargs – additional arguments inherited parser may need

Returns

value or default

Raises

config.exceptions.KVStorageValueIsEmpty – if specified endpoint does not contain a config

get_client()[source]

If your backend needs a client, inherit this method and use client() shortcut.

Returns

an instance of backend-specific client

property inner_parser: django_docker_helpers.config.backends.base.BaseParser

Prepares inner config parser for config stored at endpoint.

Return type

BaseParser

Returns

an instance of BaseParser

Raises

config.exceptions.KVStorageValueIsEmpty – if specified endpoint does not contain a config