MPT Redis Parser

class django_docker_helpers.config.backends.mpt_redis_parser.MPTRedisParser(scope=None, host='127.0.0.1', port=6379, db=0, path_separator='.', key_prefix='', object_deserialize_prefix='::YAML::\n', object_deserialize=<function default_yaml_object_deserialize>, **redis_options)[source]

Bases: django_docker_helpers.config.backends.base.BaseParser

Materialized Path Tree Redis Parser.

Compared to, e.g. RedisParser it does not load a whole config file from a single key, but reads every config option from a corresponding variable path.

Example:

parser = MPTRedisParser(host=REDIS_HOST, port=REDIS_PORT)
parser.get('nested.a.b')
parser.get('debug')

If you want to store your config with separated key paths take mp_serialize_dict() helper to materialize your dict.

Parameters:
  • scope (Optional[str]) – a global namespace-like variable prefix
  • 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 '.'
  • key_prefix (str) – prefix all keys with specified one
  • object_deserialize_prefix (str) – if object has a specified prefix, it’s deserialized with object_deserialize
  • object_deserialize (Optional[Callable]) – deserializer for complex variables
  • redis_options – additional options for redis.Redis client
__str__()[source]

Return str(self).

get(variable_path, default=None, coerce_type=None, coercer=None, **kwargs)[source]
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[+CT_co]]) – 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

get_client()[source]

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

Returns:an instance of backend-specific client