Skip to content

Commit

Permalink
feat: add redis sentinel support
Browse files Browse the repository at this point in the history
Signed-off-by: snowron <snowronark@gmail.com>
  • Loading branch information
snowron authored and achals committed Nov 14, 2023
1 parent ae1bb8b commit 4337c89
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sdk/python/feast/infra/online_stores/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
try:
from redis import Redis
from redis.cluster import ClusterNode, RedisCluster
from redis.sentinel import Sentinel
except ImportError as e:
from feast.errors import FeastExtrasDependencyImportError

Expand All @@ -54,6 +55,7 @@
class RedisType(str, Enum):
redis = "redis"
redis_cluster = "redis_cluster"
redis_sentinel = "redis_sentinel"


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

sentinel_master: StrictStr = "mymaster"
"""Sentinel's master name"""

connection_string: StrictStr = "localhost:6379"
"""Connection string containing the host, port, and configuration parameters for Redis
format: host:port,parameter1,parameter2 eg. redis:6379,db=0 """
Expand Down Expand Up @@ -178,6 +183,19 @@ def _get_client(self, online_store_config: RedisOnlineStoreConfig):
ClusterNode(**node) for node in startup_nodes
]
self._client = RedisCluster(**kwargs)
elif online_store_config.redis_type == RedisType.redis_sentinel:
sentinel_hosts = []

for item in startup_nodes:
sentinel_hosts.append((item['host'], int(item['port'])))

sentinel = Sentinel(
sentinel_hosts,
**kwargs
)

master = sentinel.master_for(online_store_config.sentinel_master)
self._client = master
else:
kwargs["host"] = startup_nodes[0]["host"]
kwargs["port"] = startup_nodes[0]["port"]
Expand Down

0 comments on commit 4337c89

Please sign in to comment.