Skip to content

feat(redis)!: remove the clear_pattern prefix fallback and the encoding option - #401

Merged
allen0099 merged 3 commits into
masterfrom
remove/125-126-redis-deprecations
Sep 29, 2026
Merged

allen0099 merged 3 commits into
masterfrom
remove/125-126-redis-deprecations

Conversation

@allen0099

Copy link
Copy Markdown
Owner

Fixes #125. Fixes #126.

#125: clear_pattern prefix fallback
0.3.8 made clear_pattern() match the logical key. The retry with the prefix-stripped pattern, and its DeprecationWarning, are gone. A pattern that starts with key_prefix now matches only logical keys that themselves start with the prefix, the same as on every other backend. The docs in docs/BACKENDS.md (EN and zh-TW) are updated.

#126: encoding option, raw bytes

  • The client is created with decode_responses=False. Replies go straight to decode_entry, which already accepted bytes, saving a decode/encode per hit. The Lua compare scripts behind delete_if_equals/expire_if_equals now receive exactly the bytes set() wrote.
  • SCAN keys are decoded as UTF-8. A non-UTF-8 key under the prefix is skipped by get_all_keys/clear_path but still removed by clear().
  • encoding= and decode_responses= passed to AsyncRedisCacheBackend raise TypeError. Otherwise they would fall through **kwargs into redis-py and switch decoding back on.
  • decode_responses never warned in 0.3.9. It only accepted True, its default, and the migration guide now says so.
  • RedisConfig drops the field and ignores an old encoding value like any other unknown field.
  • Data 0.3.x stored with the default UTF-8 encoding reads back unchanged, and a test covers it.
  • A caller-supplied pool with decode_responses=True still works.

Tests

  • New: raw-bytes client, the TypeError, non-ASCII and non-UTF-8 content round-trips, old UTF-8 JSON entries, non-UTF-8 keys, and a decoding caller pool.
  • Checks: pre-commit, mypy strict, the full suite including the Redis and Memcached suites (1517 passed, coverage 99%), and both strict docs builds.
  • An independent review found no blocking issues; its wording and test nits are fixed in a7da2c8.

Changelog: changelog.d/125.removed.md, changelog.d/126.removed.md.

@allen0099 allen0099 added this to the 0.4.0 milestone Sep 29, 2026
@allen0099 allen0099 added backends Cache backends and their atomic primitives breaking-change Changes public behaviour or API; needs a minor/major release labels Sep 29, 2026
A Redis clear_pattern() pattern now always matches the logical key; one
that starts with the backend key_prefix is no longer retried with the
prefix stripped, and the DeprecationWarning is gone.

Closes #125
AsyncRedisCacheBackend creates its client with decode_responses=False and
passes replies straight to decode_entry; SCAN keys are decoded as UTF-8
(a key that is not UTF-8 is skipped when listing or matching by path, and
still removed by clear()). The encoding and decode_responses parameters
are gone and raise TypeError instead of reaching redis-py through
**kwargs; RedisConfig loses its encoding field. Entries were always UTF-8
JSON, so stored data reads back unchanged.

Closes #126
@allen0099
allen0099 force-pushed the remove/125-126-redis-deprecations branch from a7da2c8 to d068fd2 Compare September 29, 2026 14:59
@allen0099
allen0099 merged commit 3f56e3e into master Sep 29, 2026
13 checks passed
@allen0099
allen0099 deleted the remove/125-126-redis-deprecations branch September 29, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backends Cache backends and their atomic primitives breaking-change Changes public behaviour or API; needs a minor/major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.4.0: drop the Redis encoding option and read raw bytes 0.4.0: remove the Redis clear_pattern prefix fallback

1 participant