-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for Redis and Redis Cluster #1511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d97aaea
ae9ed8e
e165f00
df8f3cb
6bea80d
5745ff7
a3c4f3b
e434e59
8ccfc6b
be9a17f
7606fe7
2a95e3e
435c856
d329439
b5269e7
f602b9a
bbde0b0
d86f23c
b0c8101
52232cc
53f8f72
e12ecff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: qooba <dev@qooba.net>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import json | ||
| import os | ||
| from datetime import datetime | ||
| from pathlib import Path | ||
|
|
@@ -32,18 +33,6 @@ class RedisProvider(Provider): | |
| def __init__(self, config: RepoConfig): | ||
| assert isinstance(config.online_store, RedisOnlineStoreConfig) | ||
|
|
||
| def _get_client(self): | ||
| if os.environ["REDIS_TYPE"] == "REDIS_CLUSTER": | ||
| return RedisCluster( | ||
| host=os.environ["REDIS_HOST"], | ||
| port=os.environ["REDIS_PORT"], | ||
| decode_responses=True, | ||
| ) | ||
| else: | ||
| return Redis( | ||
| host=os.environ["REDIS_HOST"], port=os.environ["REDIS_PORT"], db=0 | ||
| ) | ||
|
|
||
| def update_infra( | ||
| self, | ||
| project: str, | ||
|
|
@@ -54,7 +43,6 @@ def update_infra( | |
| partial: bool, | ||
| ): | ||
| client = self._get_client() | ||
| # TODO | ||
|
|
||
| def teardown_infra( | ||
| self, | ||
|
|
@@ -178,6 +166,48 @@ def materialize_single_feature_view( | |
| feature_view.materialization_intervals.append((start_date, end_date)) | ||
| registry.apply_feature_view(feature_view, project) | ||
|
|
||
| def _get_cs(self): | ||
| """ | ||
| Reads Redis connections string using format | ||
| for RedisCluster: | ||
| redis1:6379,redis2:6379,decode_responses=true,skip_full_coverage_check=true,ssl=true,password=... | ||
| for Redis: | ||
| redis_master:6379,db=0,ssl=true,password=... | ||
| """ | ||
| connection_string = os.environ["REDIS_CONNECTION_STRING"] | ||
| startup_nodes = [ | ||
| dict(zip(["host", "port"], c.split(":"))) | ||
| for c in connection_string.split(",") | ||
| if not "=" in c | ||
| ] | ||
| params = {} | ||
| for c in connection_string.split(","): | ||
| if "=" in c: | ||
| kv = c.split("=") | ||
| try: | ||
| kv[1] = json.loads(kv[1]) | ||
| except json.JSONDecodeError: | ||
| ... | ||
|
|
||
| it = iter(kv) | ||
| params.update(dict(zip(it, it))) | ||
|
|
||
| return startup_nodes, params | ||
|
|
||
| def _get_client(self): | ||
| """ | ||
| Creates the Redis client RedisCluster or Redis depending on configuration | ||
| """ | ||
| startup_nodes, kwargs = self._get_cs() | ||
|
|
||
| if os.environ["REDIS_TYPE"] == "REDIS_CLUSTER": | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We certainly should be moving to using purely There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is the goal. Also, I think we can add environmental variable loading when parsing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, that's a good idea! I agree that it's best to have a single place that all of the configuration options are visible. |
||
| kwargs["startup_nodes"] = startup_nodes | ||
| return RedisCluster(**kwargs) | ||
| else: | ||
| kwargs["host"] = startup_nodes[0]["host"] | ||
| kwargs["port"] = startup_nodes[0]["port"] | ||
| return Redis(**kwargs) | ||
|
|
||
| @staticmethod | ||
| def get_historical_features( | ||
| config: RepoConfig, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redis.pyfor the file name is fine, for consistency.