Skip to content

Commit 3d7d960

Browse files
authored
Merge pull request #35 from sopherapps/bugfix/error-multiple-redis-instances-can-be-passed-to-store
Fix possibility of Passing Multiple Redis Instances to the Store
2 parents a0f79e2 + be749d7 commit 3d7d960

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
### Changed
13+
14+
- [BREAKING CHANGE] Removed the 'redis_store' argument from the `Store` constructor
15+
- [BREAKING CHANGE] Made the 'redis_store' property of the `Store` readonly
16+
17+
### Fixed
18+
19+
- Fixed the rendering of the reference docs from the docstrings
20+
1021
## [0.5.0] - 2024-02-10
1122

1223
### Added

pydantic_redis/_shared/store.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class AbstractStore(BaseModel):
3434

3535
name: str
3636
redis_config: RedisConfig
37-
redis_store: Optional[Union[Redis, AioRedis]] = None
3837
life_span_in_seconds: Optional[int] = None
3938
select_all_fields_for_all_ids_script: Optional[Union[AsyncScript, Script]] = None
4039
paginated_select_all_fields_for_all_ids_script: Optional[
@@ -49,25 +48,31 @@ class AbstractStore(BaseModel):
4948
models: Dict[str, Type["AbstractModel"]] = {}
5049
model_config = ConfigDict(arbitrary_types_allowed=True, from_attributes=True)
5150

51+
# protected properties
52+
_redis_store: Optional[Union[Redis, AioRedis]] = None
53+
5254
def __init__(
5355
self,
5456
name: str,
5557
redis_config: RedisConfig,
56-
redis_store: Optional[Union[Redis, AioRedis]] = None,
5758
life_span_in_seconds: Optional[int] = None,
5859
**data: Any,
5960
):
6061
super().__init__(
6162
name=name,
6263
redis_config=redis_config,
63-
redis_store=redis_store,
6464
life_span_in_seconds=life_span_in_seconds,
6565
**data,
6666
)
6767

68-
self.redis_store = self._connect_to_redis()
68+
self._redis_store = self._connect_to_redis()
6969
self._register_lua_scripts()
7070

71+
@property
72+
def redis_store(self) -> Optional[Union[Redis, AioRedis]]:
73+
"""the redis store for the given store"""
74+
return self._redis_store
75+
7176
def _connect_to_redis(self) -> Union[Redis, AioRedis]:
7277
"""Connects the store to redis.
7378

pydantic_redis/asyncio/store.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class Store(AbstractStore):
3030
Model name
3131
name (str): the name of this Store
3232
redis_config (pydantic_redis.syncio.RedisConfig): the configuration for connecting to a redis database
33-
redis_store (Optional[redis.Redis]): an Redis instance associated with this store (default: None)
3433
life_span_in_seconds (Optional[int]): the default time-to-live for the records inserted in this store
3534
(default: None)
3635
"""

pydantic_redis/syncio/store.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class Store(AbstractStore):
3030
Model name
3131
name (str): the name of this Store
3232
redis_config (pydantic_redis.syncio.RedisConfig): the configuration for connecting to a redis database
33-
redis_store (Optional[redis.Redis]): an Redis instance associated with this store (default: None)
3433
life_span_in_seconds (Optional[int]): the default time-to-live for the records inserted in this store
3534
(default: None)
3635
"""

0 commit comments

Comments
 (0)