RedisTenancyBootstrapper
The RedisTenancyBootstrapper makes direct Redis calls tenant-aware — that is, calls made using the Redis facade or
a Redis connection injected as a dependency. It does this by setting a prefix on the configured Redis connections, so
each tenant’s keys are separate from other tenants’ keys.
If you use Redis only for cache, you don’t need this bootstrapper. The CacheTenancyBootstrapper
scopes cache on its own.
Enabling the bootstrapper
Section titled “Enabling the bootstrapper”To enable this bootstrapper, uncomment the RedisTenancyBootstrapper line in the bootstrappers section of the tenancy config:
'bootstrappers' => [ // Bootstrappers\RedisTenancyBootstrapper::class,],Configuration
Section titled “Configuration”The bootstrapper is configured in the redis section of the tenancy config:
'redis' => [ 'prefix' => 'tenant_%tenant%_', 'prefixed_connections' => [ 'default', // 'cache', ],],prefix is the prefix used in the tenant context, with %tenant% replaced by the tenant key.
prefixed_connections are the Redis connections (from config/database.php) that the prefix is applied to. When tenancy
is ended, the connections’ original prefixes are restored.
Adding the cache connection makes this bootstrapper scope your Redis cache as well. See the
cache bootstrapper page for details.
Sessions and queues
Section titled “Sessions and queues”If you use the redis session driver, this bootstrapper can scope your sessions — see
Session scoping.
If you use the redis queue driver, the queue has to use a connection that isn’t prefixed — see
Queue bootstrapper.