Simplify check for existing token (#765)

* Simplify check for existing token in RedisCacheHandler

* Update CHANGELOG.md
This commit is contained in:
ENT8R authored and GitHub committed 2022-01-03 19:33:13 +01:00
1 parent 08411b9031
commit 9a627e88f4
2 files changed
+4 -2

No files matched your search

+1
View File
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added `RedisCacheHandler`, a cache handler that stores the token info in Redis. * Added `RedisCacheHandler`, a cache handler that stores the token info in Redis.
* Changed URI handling in `client.Spotify._get_id()` to remove qureies if provided by error. * Changed URI handling in `client.Spotify._get_id()` to remove qureies if provided by error.
* Added a new parameter to `RedisCacheHandler` to allow custom keys (instead of the default `token_info` key) * Added a new parameter to `RedisCacheHandler` to allow custom keys (instead of the default `token_info` key)
* Simplify check for existing token in `RedisCacheHandler`
## [2.19.0] - 2021-08-12 ## [2.19.0] - 2021-08-12
+3 -2
View File
@@ -166,8 +166,9 @@ class RedisCacheHandler(CacheHandler):
def get_cached_token(self): def get_cached_token(self):
token_info = None token_info = None
try: try:
if self.redis.exists(self.key): token_info = self.redis.get(self.key)
token_info = json.loads(self.redis.get(self.key)) if token_info:
return json.loads(token_info)
except RedisError as e: except RedisError as e:
logger.warning('Error getting token from cache: ' + str(e)) logger.warning('Error getting token from cache: ' + str(e))