Skip to content

Commit

Permalink
feat(keys): keep keys sorted and fix key format (#28)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: key format fix
  • Loading branch information
taylorhakes committed Jan 9, 2024
1 parent a5b5774 commit aa554ee
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commit_message_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
no-jira: true
no_jira: true
4 changes: 2 additions & 2 deletions redis_cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from inspect import signature

def compact_dump(value):
return dumps(value, separators=(',', ':'))
return dumps(value, separators=(',', ':'), sort_keys=True)

def get_args(fn, args, kwargs):
"""
Expand Down Expand Up @@ -168,7 +168,7 @@ def __init__(self, redis_client, prefix="rc", serializer=compact_dump, deseriali


def get_full_prefix(self):
return f'{{{self.prefix}:{self.namespace}}}'
return f'{self.prefix}:{self.namespace}'

def get_key(self, args, kwargs):
normalized_args = get_args(self.original_fn, args, kwargs)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_redis_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def add_custom_key_serializer(arg1, arg2):
encoded_args = b64encode("{'arg1': 2, 'arg2': 3}".encode('utf-8')).decode('utf-8')

assert r1 == r2
assert client.exists(f'{{rc:test_redis_cache.test_custom_key_serializer.<locals>.add_custom_key_serializer}}:{encoded_args}')
assert client.exists(f'rc:test_redis_cache.test_custom_key_serializer.<locals>.add_custom_key_serializer:{encoded_args}')


def test_basic_mget(cache):
Expand Down

0 comments on commit aa554ee

Please sign in to comment.