diff --git a/HISTORY.rst b/HISTORY.rst index 2042a26..f76d2b4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,12 @@ History ======= +v0.12.4 (2021-03-17) +----------------------- + +* Add ability to set encoding on Redis client. + + v0.12.3 (2021-03-12) ----------------------- diff --git a/aioradio/redis.py b/aioradio/redis.py index 559bf68..5268f2a 100644 --- a/aioradio/redis.py +++ b/aioradio/redis.py @@ -46,9 +46,12 @@ class Redis: def __post_init__(self): primary_endpoint = self.config["redis_primary_endpoint"] - self.pool = redis.Redis(host=primary_endpoint) + if "encoding" in self.config: + self.pool = redis.Redis(host=primary_endpoint, encoding=self.config["encoding"], decode_responses=True) + else: + self.pool = redis.Redis(host=primary_endpoint) - async def get(self, key: str, use_json: bool=None, encoding: Union[str, None]='utf-8') -> Any: + async def get(self, key: str, use_json: bool=None, encoding: Union[str, None]=None) -> Any: """Check if an item is cached in redis. Args: @@ -73,7 +76,7 @@ async def get(self, key: str, use_json: bool=None, encoding: Union[str, None]='u return value - async def mget(self, items: List[str], use_json: bool=None, encoding: Union[str, None]='utf-8') -> List[Any]: + async def mget(self, items: List[str], use_json: bool=None, encoding: Union[str, None]=None) -> List[Any]: """Check if many items are cached in redis. Args: @@ -137,7 +140,7 @@ async def delete(self, key: str) -> int: return self.pool.delete(key) - async def hget(self, key: str, field: str, use_json: bool=None, encoding: Union[str, None]='utf-8') -> Any: + async def hget(self, key: str, field: str, use_json: bool=None, encoding: Union[str, None]=None) -> Any: """Get the value of a hash field. Args: @@ -163,7 +166,7 @@ async def hget(self, key: str, field: str, use_json: bool=None, encoding: Union[ return value - async def hmget(self, key: str, fields: List[str], use_json: bool=None, encoding: Union[str, None]='utf-8') -> Any: + async def hmget(self, key: str, fields: List[str], use_json: bool=None, encoding: Union[str, None]=None) -> Any: """Get the values of all the given fields. Args: @@ -190,7 +193,7 @@ async def hmget(self, key: str, fields: List[str], use_json: bool=None, encoding return items - async def hmget_many(self, keys: List[str], fields: List[str], use_json: bool=None, encoding: Union[str, None]='utf-8') -> List[Any]: + async def hmget_many(self, keys: List[str], fields: List[str], use_json: bool=None, encoding: Union[str, None]=None) -> List[Any]: """Get the values of all the given fields for many hashed keys. Args: @@ -224,7 +227,7 @@ async def hmget_many(self, keys: List[str], fields: List[str], use_json: bool=No return results - async def hgetall(self, key: str, use_json: bool=None, encoding: Union[str, None]='utf-8') -> Any: + async def hgetall(self, key: str, use_json: bool=None, encoding: Union[str, None]=None) -> Any: """Get all the fields and values in a hash. Args: @@ -252,7 +255,7 @@ async def hgetall(self, key: str, use_json: bool=None, encoding: Union[str, None return items - async def hgetall_many(self, keys: List[str], use_json: bool=None, encoding: Union[str, None]='utf-8') -> List[Any]: + async def hgetall_many(self, keys: List[str], use_json: bool=None, encoding: Union[str, None]=None) -> List[Any]: """Get all the fields and values in a hash. Args: diff --git a/aioradio/requirements.txt b/aioradio/requirements.txt index 3dd1ee0..ae05c5e 100644 --- a/aioradio/requirements.txt +++ b/aioradio/requirements.txt @@ -3,8 +3,7 @@ aiobotocore==1.1.2 aiojobs==0.3.0 ddtrace==0.47.0 flask==1.1.2 -git+https://github.com/aio-libs/aioredis@sean/aioredis-redis-py-compliance -httpx==0.17.0 +httpx==0.17.1 mandrill==1.0.59 moto==1.3.16 orjson==3.5.1 @@ -18,5 +17,5 @@ pytest-asyncio==0.14.0 pytest-cov==2.11.1 python-json-logger==2.0.1 redis==3.5.3 -twine==3.3.0 +twine==3.4.1 wheel==0.36.2 diff --git a/conftest.py b/conftest.py index ef14330..7554487 100644 --- a/conftest.py +++ b/conftest.py @@ -57,7 +57,8 @@ def cache(github_action): pytest.skip('Skip test_set_one_item when running via Github Action') cache_object = Redis(config={ - 'redis_primary_endpoint': 'prod-race2.gbngr1.ng.0001.use1.cache.amazonaws.com' + 'redis_primary_endpoint': 'prod-race2.gbngr1.ng.0001.use1.cache.amazonaws.com', + 'encoding': 'utf-8' }) yield cache_object diff --git a/setup.py b/setup.py index 85d84cc..3f07d13 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ long_description = fileobj.read() setup(name='aioradio', - version='0.12.3', + version='0.12.4', description='Generic asynchronous i/o python utilities for AWS services (SQS, S3, DynamoDB, Secrets Manager), Redis, MSSQL (pyodbc), JIRA and more', long_description=long_description, long_description_content_type="text/markdown",