Skip to content

Add configurable encoder classes to standalone clients - #4221

Draft
lh0156 wants to merge 1 commit into
redis:masterfrom
lh0156:agent/configurable-encoder-3181
Draft

Add configurable encoder classes to standalone clients#4221
lh0156 wants to merge 1 commit into
redis:masterfrom
lh0156:agent/configurable-encoder-3181

Conversation

@lh0156

@lh0156 lh0156 commented Jul 26, 2026

Copy link
Copy Markdown

What

Adds support for configuring a custom Encoder subclass on standalone sync and asyncio clients and their connection pools.

Closes #3181

Why

The default encoder rejects application-specific Python value types. Users can now implement custom serialization/deserialization while retaining redis-py's existing encoding configuration.

Design

  • Adds encoder_class to sync and asyncio Redis constructors.
  • Propagates the class to the connection pool and connection instances.
  • Instantiates an encoder per connection/helper instead of sharing mutable encoder instances.
  • Exposes Encoder from redis and redis.asyncio.
  • Preserves the default Encoder behavior when no custom class is supplied.
  • Documents the connection-isolation contract.
  • Limits this change to standalone clients and pools; Cluster/Sentinel behavior is unchanged.

Tests

  • Added sync and asyncio regression coverage for:
    • custom encoding and decoding
    • pool-created connection encoders
    • pool helper encoders being distinct instances
    • client-to-pool configuration propagation
  • 157 passed, 4 skipped for tests/test_connection.py tests/test_asyncio/test_connection.py
  • 17 passed for tests/test_client.py tests/test_asyncio/test_client.py
  • Ruff check/format, compileall, and git diff --check pass.

This is a draft while CI and maintainer feedback run.

@lh0156 lh0156 mentioned this pull request Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configurable Encoder

1 participant