https://github.com/macpaw/redis-schema-bundle
Redis schema bundle
https://github.com/macpaw/redis-schema-bundle
backend macpaw symfony
Last synced: 5 months ago
JSON representation
Redis schema bundle
- Host: GitHub
- URL: https://github.com/macpaw/redis-schema-bundle
- Owner: MacPaw
- Created: 2025-07-03T18:09:21.000Z (12 months ago)
- Default Branch: develop
- Last Pushed: 2025-08-01T11:24:01.000Z (11 months ago)
- Last Synced: 2025-08-18T10:55:25.640Z (11 months ago)
- Topics: backend, macpaw, symfony
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Redis Schema Bundle
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](https://github.com/macpaw/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` and `AdapterInterface`
- Supports schema-based multitenancy
---
## Installation
```bash
composer require macpaw/redis-schema-bundle
```
If you are not using Symfony Flex, register the bundle manually:
```php
// 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:
```yaml
# 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\BaggageSchemaResolver'
```
## 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:
```php
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:
```bash
vendor/bin/phpunit
```
## Contributing
Feel free to open issues and submit pull requests.
## License
This bundle is released under the MIT license.