Skip to content

Commit

Permalink
Fix redis-cache.py for python 3
Browse files Browse the repository at this point in the history
Encode and decode UTF-8 text data instead of using
the python3 default binary data type, which prevents
comparisons working the way we expect.
  • Loading branch information
jmurty committed Jun 5, 2018
1 parent db20942 commit 32a62e8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ixc_django_docker/bin/redis-cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ def fault(parser, logger, message=None):
sys.exit(1)


def redis_set(conn, key, value, expiry_secs):
def redis_set(conn, key, value, expiry_secs, encoding='utf-8'):
if encoding:
value = value.encode(encoding)
return conn.set(key, value, ex=expiry_secs)


def redis_get(conn, key):
return conn.get(key)
def redis_get(conn, key, encoding='utf-8'):
value = conn.get(key)
if encoding:
value = value.decode('utf-8')
return value


def main():
Expand Down

0 comments on commit 32a62e8

Please sign in to comment.