43
43
try :
44
44
from redis import Redis
45
45
from redis .cluster import ClusterNode , RedisCluster
46
+ from redis .sentinel import Sentinel
46
47
except ImportError as e :
47
48
from feast .errors import FeastExtrasDependencyImportError
48
49
54
55
class RedisType (str , Enum ):
55
56
redis = "redis"
56
57
redis_cluster = "redis_cluster"
58
+ redis_sentinel = "redis_sentinel"
57
59
58
60
59
61
class RedisOnlineStoreConfig (FeastConfigBaseModel ):
@@ -65,6 +67,9 @@ class RedisOnlineStoreConfig(FeastConfigBaseModel):
65
67
redis_type : RedisType = RedisType .redis
66
68
"""Redis type: redis or redis_cluster"""
67
69
70
+ sentinel_master : StrictStr = "mymaster"
71
+ """Sentinel's master name"""
72
+
68
73
connection_string : StrictStr = "localhost:6379"
69
74
"""Connection string containing the host, port, and configuration parameters for Redis
70
75
format: host:port,parameter1,parameter2 eg. redis:6379,db=0 """
@@ -178,6 +183,19 @@ def _get_client(self, online_store_config: RedisOnlineStoreConfig):
178
183
ClusterNode (** node ) for node in startup_nodes
179
184
]
180
185
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
181
199
else :
182
200
kwargs ["host" ] = startup_nodes [0 ]["host" ]
183
201
kwargs ["port" ] = startup_nodes [0 ]["port" ]
0 commit comments