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:
19
hyperglass/cache/aio.py
vendored
19
hyperglass/cache/aio.py
vendored
@@ -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."""
|
||||
|
2
hyperglass/cache/base.py
vendored
2
hyperglass/cache/base.py
vendored
@@ -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
|
||||
|
19
hyperglass/cache/sync.py
vendored
19
hyperglass/cache/sync.py
vendored
@@ -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."""
|
||||
|
Reference in New Issue
Block a user