Skip to content

Commit

Permalink
feat(keys): keep keys sorted and fix key format
Browse files Browse the repository at this point in the history
BREAKING CHANGE: key format fix
  • Loading branch information
taylorhakes committed Dec 23, 2023
1 parent db88117 commit 1654277
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
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 1654277

Please sign in to comment.