redis_store_base
Base Classes for Redis-Backed Data Stores in Merlin
This module provides foundational classes for implementing Redis-based persistence in the Merlin system. It defines reusable components that standardize how data models are stored, retrieved, and managed in Redis.
See also
- merlin.backends.store_base: Base class
- merlin.backends.redis.redis_stores: Concrete store implementations
- merlin.db_scripts.data_models: Data model definitions
NameMappingMixin
Mixin class that adds name-to-ID mapping functionality to Redis stores.
This mixin extends Redis stores to support retrieval and deletion by name.
Methods:
| Name | Description |
|---|---|
save |
Save or update an entity in the database. |
retrieve |
Retrieve an entity from the database by ID or name. |
delete |
Delete an entity from the database by ID or name. |
Source code in merlin/backends/redis/redis_store_base.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
delete(identifier, by_name=False)
Delete an entity from the Redis database, either by ID or name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The ID or name of the entity to delete. |
required |
by_name
|
bool
|
If True, interpret the identifier as a name. If False, interpret it as an ID. |
False
|
Source code in merlin/backends/redis/redis_store_base.py
retrieve(identifier, by_name=False)
Retrieve an entity from the Redis database, either by ID or name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The ID or name of the entity to retrieve. |
required |
by_name
|
bool
|
If True, interpret the identifier as a name. If False, interpret it as an ID. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[T]
|
The entity if found, None otherwise. |
Source code in merlin/backends/redis/redis_store_base.py
save(entity)
Save an entity and update the name-to-ID mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
Type[T]
|
The entity to save. |
required |
Source code in merlin/backends/redis/redis_store_base.py
RedisStoreBase
Bases: StoreBase[T], Generic[T]
Base class for Redis-based stores.
This class provides common functionality for saving, retrieving, and deleting entities in a Redis database.
Attributes:
| Name | Type | Description |
|---|---|---|
client |
Redis
|
The Redis client used for database operations. |
key |
str
|
The prefix key used for Redis entries. |
model_class |
Type[T]
|
The model class used for deserialization. |
Methods:
| Name | Description |
|---|---|
save |
Save or update an entity in the database. |
retrieve |
Retrieve an entity from the database by ID. |
retrieve_all |
Query the database for all entities of this type. |
delete |
Delete an entity from the database by ID. |
Source code in merlin/backends/redis/redis_store_base.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
__init__(client, key, model_class)
Initialize the Redis store with a Redis client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Redis
|
A Redis client instance used to interact with the Redis database. |
required |
key
|
str
|
The prefix key used for Redis entries. |
required |
model_class
|
Type[T]
|
The model class used for deserialization. |
required |
Source code in merlin/backends/redis/redis_store_base.py
delete(identifier)
Delete an entity from the Redis database by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The ID of the entity to delete. |
required |
Source code in merlin/backends/redis/redis_store_base.py
retrieve(identifier)
Retrieve an entity from the Redis database by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
The ID of the entity to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Optional[T]
|
The entity if found, None otherwise. |
Source code in merlin/backends/redis/redis_store_base.py
retrieve_all()
Query the Redis database for all entities of this type.
Returns:
| Type | Description |
|---|---|
List[T]
|
A list of entities. |
Source code in merlin/backends/redis/redis_store_base.py
save(entity)
Save or update an entity in the Redis database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
T
|
The entity to save. |
required |