-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from qld-gov-au/develop
[QOL-8518] [QOL-8612] Multiple fixes (Redis ignore exceptions, speed improvements, cleanup s3 acl flags)
- Loading branch information
Showing
12 changed files
with
473 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# encoding: utf-8 | ||
|
||
import logging | ||
import six | ||
|
||
from ckan.lib.redis import connect_to_redis | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
REDIS_PREFIX = 'ckanext-s3filestore:' | ||
|
||
|
||
class RedisHelper: | ||
|
||
def _get_cache_key(self, path): | ||
return REDIS_PREFIX + path | ||
|
||
def get(self, key): | ||
''' Get a value from the cache, if available. | ||
Returned values will be converted to text type instead of bytes. | ||
''' | ||
cache_key = self._get_cache_key(key) | ||
try: | ||
redis_conn = connect_to_redis() | ||
cache_value = redis_conn.get(cache_key) | ||
except Exception as e: | ||
log.error("Failed to connect to Redis cache: %s", e) | ||
cache_value = None | ||
if cache_value is not None and hasattr(six, 'ensure_text'): | ||
cache_value = six.ensure_text(cache_value) | ||
return cache_value | ||
|
||
def put(self, key, value, expiry=None): | ||
''' Set a URL value in the cache, if available, with the | ||
specified expiry. If expiry is None, no action is taken. | ||
''' | ||
if expiry: | ||
cache_key = self._get_cache_key(key) | ||
try: | ||
redis_conn = connect_to_redis() | ||
redis_conn.set(cache_key, value, ex=expiry) | ||
except Exception as e: | ||
log.error("Failed to connect to Redis cache: %s", e) | ||
|
||
def delete(self, key): | ||
''' Delete a value from the cache, if available. | ||
''' | ||
cache_key = self._get_cache_key(key) | ||
try: | ||
redis_conn = connect_to_redis() | ||
redis_conn.delete(cache_key) | ||
except Exception as e: | ||
log.error("Failed to connect to Redis cache: %s", e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.