Skip to content

Commit

Permalink
Add ability to set encoding on Redis client
Browse files Browse the repository at this point in the history
  • Loading branch information
tim.reichard committed Mar 17, 2021
1 parent cf37d12 commit 167001d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-----------------------

Expand Down
19 changes: 11 additions & 8 deletions aioradio/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions aioradio/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 167001d

Please sign in to comment.