Skip to content

Commit 4337c89

Browse files
snowronachals
authored andcommitted
feat: add redis sentinel support
Signed-off-by: snowron <snowronark@gmail.com>
1 parent ae1bb8b commit 4337c89

File tree

1 file changed

+18
-0
lines changed
  • sdk/python/feast/infra/online_stores

1 file changed

+18
-0
lines changed

sdk/python/feast/infra/online_stores/redis.py

+18
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
try:
4444
from redis import Redis
4545
from redis.cluster import ClusterNode, RedisCluster
46+
from redis.sentinel import Sentinel
4647
except ImportError as e:
4748
from feast.errors import FeastExtrasDependencyImportError
4849

@@ -54,6 +55,7 @@
5455
class RedisType(str, Enum):
5556
redis = "redis"
5657
redis_cluster = "redis_cluster"
58+
redis_sentinel = "redis_sentinel"
5759

5860

5961
class RedisOnlineStoreConfig(FeastConfigBaseModel):
@@ -65,6 +67,9 @@ class RedisOnlineStoreConfig(FeastConfigBaseModel):
6567
redis_type: RedisType = RedisType.redis
6668
"""Redis type: redis or redis_cluster"""
6769

70+
sentinel_master: StrictStr = "mymaster"
71+
"""Sentinel's master name"""
72+
6873
connection_string: StrictStr = "localhost:6379"
6974
"""Connection string containing the host, port, and configuration parameters for Redis
7075
format: host:port,parameter1,parameter2 eg. redis:6379,db=0 """
@@ -178,6 +183,19 @@ def _get_client(self, online_store_config: RedisOnlineStoreConfig):
178183
ClusterNode(**node) for node in startup_nodes
179184
]
180185
self._client = RedisCluster(**kwargs)
186+
elif online_store_config.redis_type == RedisType.redis_sentinel:
187+
sentinel_hosts = []
188+
189+
for item in startup_nodes:
190+
sentinel_hosts.append((item['host'], int(item['port'])))
191+
192+
sentinel = Sentinel(
193+
sentinel_hosts,
194+
**kwargs
195+
)
196+
197+
master = sentinel.master_for(online_store_config.sentinel_master)
198+
self._client = master
181199
else:
182200
kwargs["host"] = startup_nodes[0]["host"]
183201
kwargs["port"] = startup_nodes[0]["port"]

0 commit comments

Comments
 (0)