Skip to content

Commit e0d76ff

Browse files
committed
Add support for extra Redis connection params
1 parent 8d50196 commit e0d76ff

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

ldclient/impl/integrations/redis/redis_big_segment_store.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from ldclient import log
22
from ldclient.interfaces import BigSegmentStore, BigSegmentStoreMetadata
33

4-
from typing import Optional, Set, cast
4+
from typing import Any, Optional, Set, cast
55

66
have_redis = False
77
try:
@@ -16,11 +16,11 @@ class _RedisBigSegmentStore(BigSegmentStore):
1616
KEY_USER_INCLUDE = ':big_segment_include:'
1717
KEY_USER_EXCLUDE = ':big_segment_exclude:'
1818

19-
def __init__(self, url: str, prefix: Optional[str], max_connections: int):
19+
def __init__(self, url: str, prefix: Optional[str], **conn_options: Any):
2020
if not have_redis:
2121
raise NotImplementedError("Cannot use Redis Big Segment store because redis package is not installed")
2222
self._prefix = prefix or 'launchdarkly'
23-
self._pool = redis.ConnectionPool.from_url(url=url, max_connections=max_connections)
23+
self._pool = redis.ConnectionPool.from_url(url=url, **conn_options)
2424
log.info("Started RedisBigSegmentStore connected to URL: " + url + " using prefix: " + self._prefix)
2525

2626
def get_metadata(self) -> BigSegmentStoreMetadata:

ldclient/impl/integrations/redis/redis_feature_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414

1515
class _RedisFeatureStoreCore(DiagnosticDescription, FeatureStoreCore):
16-
def __init__(self, url, prefix, max_connections):
16+
def __init__(self, url, prefix, **conn_options):
1717
if not have_redis:
1818
raise NotImplementedError("Cannot use Redis feature store because redis package is not installed")
1919
self._prefix = prefix or 'launchdarkly'
20-
self._pool = redis.ConnectionPool.from_url(url=url, max_connections=max_connections)
20+
self._pool = redis.ConnectionPool.from_url(url=url, **conn_options)
2121
self.test_update_hook = None # exposed for testing
2222
log.info("Started RedisFeatureStore connected to URL: " + url + " using prefix: " + self._prefix)
2323

ldclient/integrations/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,13 @@ class Redis:
144144
def new_feature_store(url: str='redis://localhost:6379/0',
145145
prefix: str='launchdarkly',
146146
max_connections: int=16,
147-
caching: CacheConfig=CacheConfig.default()) -> CachingStoreWrapper:
147+
caching: CacheConfig=CacheConfig.default(),
148+
**conn_options: Any) -> CachingStoreWrapper:
148149
"""
149150
Creates a Redis-backed implementation of :class:`~ldclient.interfaces.FeatureStore`.
150151
For more details about how and why you can use a persistent feature store, see the
151152
`SDK reference guide <https://docs.launchdarkly.com/sdk/concepts/data-stores>`_.
153+
`SDK reference guide <https://docs.launchdarkly.com/sdk/concepts/data-stores>`_.
152154
153155
To use this method, you must first install the ``redis`` package. Then, put the object
154156
returned by this method into the ``feature_store`` property of your client configuration
@@ -167,16 +169,19 @@ def new_feature_store(url: str='redis://localhost:6379/0',
167169
connection pool; defaults to ``DEFAULT_MAX_CONNECTIONS``
168170
:param caching: specifies whether local caching should be enabled and if so,
169171
sets the cache properties; defaults to :func:`ldclient.feature_store.CacheConfig.default()`
172+
:param conn_options: extra options for initializing Redis connection from the url,
173+
see `redis.connection.ConnectionPool.from_url` for more details.
170174
"""
171-
core = _RedisFeatureStoreCore(url, prefix, max_connections)
175+
core = _RedisFeatureStoreCore(url, prefix, max_connections, **conn_options)
172176
wrapper = CachingStoreWrapper(core, caching)
173177
wrapper._core = core # exposed for testing
174178
return wrapper
175179

176180
@staticmethod
177181
def new_big_segment_store(url: str='redis://localhost:6379/0',
178182
prefix: str='launchdarkly',
179-
max_connections: int=16) -> BigSegmentStore:
183+
max_connections: int=16,
184+
**conn_options: Any) -> BigSegmentStore:
180185
"""
181186
Creates a Redis-backed Big Segment store.
182187
@@ -198,8 +203,10 @@ def new_big_segment_store(url: str='redis://localhost:6379/0',
198203
``DEFAULT_PREFIX``
199204
:param max_connections: the maximum number of Redis connections to keep in the
200205
connection pool; defaults to ``DEFAULT_MAX_CONNECTIONS``
206+
:param conn_options: extra options for initializing Redis connection from the url,
207+
see `redis.connection.ConnectionPool.from_url` for more details.
201208
"""
202-
return _RedisBigSegmentStore(url, prefix, max_connections)
209+
return _RedisBigSegmentStore(url, prefix, max_connections, **conn_options)
203210

204211
class Files:
205212
"""Provides factory methods for integrations with filesystem data.

0 commit comments

Comments
 (0)