macpaw / redis-schema-bundle
A Symfony bundle to add schema prefixes for redis keys
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.3
- macpaw/schema-context-bundle: ^1.0
- symfony/cache: ^6.4|^7.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: 3.7.*
This package is auto-updated.
Last update: 2025-08-01 11:24:05 UTC
README
The Redis Schema Bundle provides automatic Redis key namespacing based on the current schema context, allowing data isolation in shared environments (e.g., staging, preview, multi-tenant).
This bundle builds on top of Schema Context Bundle to propagate the schema context across the app and decorate your Redis cache.
Features
- Transparent key prefixing for Redis
- Compatible with
Symfony\Component\Cache\Adapter\RedisAdapter
- Works with Symfony
CacheInterface
andAdapterInterface
- Supports schema-based multitenancy
Installation
composer require macpaw/redis-schema-bundle
If you are not using Symfony Flex, register the bundle manually:
// config/bundles.php return [ Macpaw\SchemaContextBundle\SchemaContextBundle::class => ['all' => true], Macpaw\RedisSchemaBundle\RedisSchemaBundle::class => ['all' => true], ];
Configuration
Make sure to register the base Redis adapter and decorate it with the schema-aware implementation:
# config/services.yaml services: redis_cache_adapter: class: Symfony\Component\Cache\Adapter\RedisAdapter arguments: - '@SymfonyBundles\RedisBundle\Redis\ClientInterface' - 'cache_storage' - '%redis_default_cache_ttl%' Macpaw\RedisSchemaBundle\Redis\SchemaAwareRedisAdapter: decorates: Symfony\Component\Cache\Adapter\RedisAdapter arguments: - '@.inner' - '@Macpaw\SchemaContextBundle\Service\SchemaResolver'
Usage
Anywhere you use Symfony cache services (injected via CacheInterface or AdapterInterface), your keys will automatically be prefixed based on the current schema. For example:
public function __construct(private CacheInterface $cache) {} public function save(): void { $this->cache->get('user.123', function () { return 'value'; }); }
If the schema is client_a, this will store key: client_a.user.123.
Testing
To run tests:
vendor/bin/phpunit
Contributing
Feel free to open issues and submit pull requests.
License
This bundle is released under the MIT license.