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]¶
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 prefixhost (
str
) – redis host, default is'127.0.0.1'
port (
int
) – redis port, default id6379
db (
int
) – redis database, default is0
path_separator (
str
) – specifies which character separates nested variables, default is'.'
key_prefix (
str
) – prefix all keys with specified oneobject_deserialize_prefix (
str
) – if object has a specified prefix, it’s deserialized withobject_deserialize
object_deserialize (
Optional
[Callable
]) – deserializer for complex variablesredis_options – additional options for
redis.Redis
client
- get(variable_path, default=None, coerce_type=None, coercer=None, **kwargs)[source]¶
- Parameters
variable_path (
str
) – a delimiter-separated path to a nested valuedefault (
Optional
[Any
]) – default value if there’s no object by specified pathcoerce_type (
Optional
[Type
]) – cast a type of a value to a specified onecoercer (
Optional
[Callable
]) – perform a type casting with specified callbackkwargs – additional arguments inherited parser may need
- Returns
value or default