EngineConfiguration_KeyValueService
What it is
Configuration models and loader logic for constructing a KeyValueService with a pluggable key-value adapter (redis, python, or custom), using Pydantic validation.
Public API
KeyValueAdapterRedisConfiguration(pydanticBaseModel)- Validates configuration for the Redis adapter.
- Fields:
redis_url: str(default:"redis://localhost:6379")
KeyValueAdapterPythonConfiguration(pydanticBaseModel)- Validates configuration for the Python adapter.
- Fields:
persistence_path: str | None(default:None)journal_mode: Literal["DELETE","TRUNCATE","PERSIST","MEMORY","WAL","OFF"](default:"WAL")busy_timeout_ms: int(default:5000)
KeyValueAdapterConfiguration(GenericLoader)- Selects an adapter type and validates/loads the corresponding adapter implementation.
- Attributes:
adapter: Literal["redis", "python", "custom"]config: dict | None
- Methods:
validate_adapter() -> KeyValueAdapterConfiguration(Pydantic@model_validator(mode="after"))- Enforces
configpresence unlessadapter == "custom". - Validates
configshape forredis/pythonviapydantic_model_validator.
- Enforces
load() -> IKeyValueAdapter- Lazily imports and instantiates:
RedisAdapter(**config)whenadapter == "redis"PythonAdapter(**config)whenadapter == "python"
- Delegates to
GenericLoader.load()whenadapter == "custom".
- Lazily imports and instantiates:
KeyValueServiceConfiguration(pydanticBaseModel)- Wraps adapter configuration and constructs the
KeyValueService. - Attributes:
kv_adapter: KeyValueAdapterConfiguration
- Methods:
load() -> KeyValueService— returnsKeyValueService(adapter=kv_adapter.load()).
- Wraps adapter configuration and constructs the
Configuration/Dependencies
- Pydantic is used for schema validation; models use
extra="forbid"for adapter-specific configs. - Adapter implementations are imported lazily from:
naas_abi_core.services.keyvalue.adapters.secondary.RedisAdapter.RedisAdapternaas_abi_core.services.keyvalue.adapters.secondary.PythonAdapter.PythonAdapter
customadapter path relies onGenericLoaderbehavior (not defined in this file).
Usage
from naas_abi_core.engine.engine_configuration.EngineConfiguration_KeyValueService import (
KeyValueServiceConfiguration,
KeyValueAdapterConfiguration,
)
# Redis-backed KeyValueService
cfg = KeyValueServiceConfiguration(
kv_adapter=KeyValueAdapterConfiguration(
adapter="redis",
config={"redis_url": "redis://localhost:6379"},
)
)
service = cfg.load()
from naas_abi_core.engine.engine_configuration.EngineConfiguration_KeyValueService import (
KeyValueServiceConfiguration,
KeyValueAdapterConfiguration,
)
# Python-backed KeyValueService
cfg = KeyValueServiceConfiguration(
kv_adapter=KeyValueAdapterConfiguration(
adapter="python",
config={
"persistence_path": None,
"journal_mode": "WAL",
"busy_timeout_ms": 5000,
},
)
)
service = cfg.load()
Caveats
configis required foradapter="redis"andadapter="python"; it may be omitted only foradapter="custom".- For adapter-specific config models, unknown keys are rejected (
extra="forbid"). load()raisesValueErrorfor unknown non-custom adapter values.