1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

closes #56 - fix redis connection error due to invalid host type

This commit is contained in:
checktheroads
2020-07-28 09:49:13 -07:00
parent 8164ec8d36
commit 7c8369a316
3 changed files with 25 additions and 15 deletions

View File

@@ -10,9 +10,11 @@ from typing import Any, Dict
# Third Party
from aredis import StrictRedis as AsyncRedis
from aredis.pubsub import PubSub as AsyncPubSub
from aredis.exceptions import RedisError
# Project
from hyperglass.cache.base import BaseCache
from hyperglass.exceptions import HyperglassError
class AsyncCache(BaseCache):
@@ -21,13 +23,16 @@ class AsyncCache(BaseCache):
def __init__(self, *args, **kwargs):
"""Initialize Redis connection."""
super().__init__(*args, **kwargs)
self.instance: AsyncRedis = AsyncRedis(
db=self.db,
host=self.host,
port=self.port,
decode_responses=self.decode_responses,
**self.redis_args,
)
try:
self.instance: AsyncRedis = AsyncRedis(
db=self.db,
host=self.host,
port=self.port,
decode_responses=self.decode_responses,
**self.redis_args,
)
except RedisError as err:
raise HyperglassError(str(err), level="danger")
async def get(self, *args: str) -> Any:
"""Get item(s) from cache."""

View File

@@ -19,7 +19,7 @@ class BaseCache:
) -> None:
"""Initialize Redis connection."""
self.db: int = db
self.host: str = host
self.host: str = str(host)
self.port: int = port
self.decode_responses: bool = decode_responses
self.redis_args: dict = kwargs

View File

@@ -9,9 +9,11 @@ from typing import Any, Dict
# Third Party
from redis import Redis as SyncRedis
from redis.client import PubSub as SyncPubsSub
from redis.exceptions import RedisError
# Project
from hyperglass.cache.base import BaseCache
from hyperglass.exceptions import HyperglassError
class SyncCache(BaseCache):
@@ -20,13 +22,16 @@ class SyncCache(BaseCache):
def __init__(self, *args, **kwargs):
"""Initialize Redis connection."""
super().__init__(*args, **kwargs)
self.instance: SyncRedis = SyncRedis(
db=self.db,
host=self.host,
port=self.port,
decode_responses=self.decode_responses,
**self.redis_args,
)
try:
self.instance: SyncRedis = SyncRedis(
db=self.db,
host=self.host,
port=self.port,
decode_responses=self.decode_responses,
**self.redis_args,
)
except RedisError as err:
raise HyperglassError(str(err), level="danger")
def get(self, *args: str) -> Any:
"""Get item(s) from cache."""