Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keep keys sorted. fix key format #28

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading