Skip to content

feat(config): add per-client class override option#760

Open
guillaumedelre wants to merge 2 commits into
snc:masterfrom
guillaumedelre:feat/per-client-class-override
Open

feat(config): add per-client class override option#760
guillaumedelre wants to merge 2 commits into
snc:masterfrom
guillaumedelre:feat/per-client-class-override

Conversation

@guillaumedelre
Copy link
Copy Markdown

Summary

  • Add an optional class key to the client configuration to allow specifying a custom client class per client
  • The option takes precedence over the global snc_redis.class.client / snc_redis.class.phpredis_client settings
  • Works for predis, phpredis and relay client types

Motivation

Closes #729 — there was no way to override the instantiated class for a specific client without writing a compiler pass. This adds a straightforward config option:

snc_redis:
    clients:
        default:
            type: predis
            dsn: redis://localhost
            class: App\Redis\CustomPredisClient   # must extend Predis\Client
        cache:
            type: phpredis
            dsn: redis://localhost
            class: App\Redis\CustomRedis          # must extend Redis

Test plan

  • testPredisCustomClass — verifies the DI definition uses the configured class for a predis client
  • testPhpRedisCustomClass — verifies the DI definition uses the configured class for a phpredis client
  • Full test suite: no regressions (43 tests in SncRedisExtensionTest, same 5 pre-existing failures due to ext-redis unavailable locally)
  • PHPCS clean
  • Psalm: no new errors vs baseline

Add an optional `class` key to the client configuration, allowing users
to specify a custom client class for each client individually.

Previously the only way to override the instantiated class was via a
compiler pass. This change makes it possible through config:

    snc_redis:
        clients:
            default:
                type: predis
                dsn: redis://localhost
                class: App\Redis\CustomPredisClient

The `class` option takes precedence over the global
`snc_redis.class.client` / `snc_redis.class.phpredis_client` settings
and applies to predis, phpredis and relay client types.

Closes snc#729

Signed-off-by: Guillaume Delré <delre.guillaume@gmail.com>
Comment thread tests/DependencyInjection/SncRedisExtensionTest.php Outdated
Comment thread docs/README.md Outdated
Replace two separate `testPredisCustomClass` / `testPhpRedisCustomClass`
methods with a single `@testWith` parametrized test using non-default
class names, so the tests actually exercise the override rather than
confirming the default.

Move the `class` option out of its own docs section and into the
Complete configuration example.

Signed-off-by: Guillaume Delré <delre.guillaume@gmail.com>
@guillaumedelre guillaumedelre requested a review from ostrolucky May 11, 2026 14:48
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.

Use custom predis or phpredis implementation

2 participants