mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-14 01:44:03 +00:00
Add Predis support (#59)
* wip * Add Predis support * Enable phpredis extension only for some builds * Add note about phpredis * Fix if command * Revert travis changes & add a version check to predis tests
This commit is contained in:
parent
e7b5a77a6b
commit
1b6759084f
9 changed files with 75 additions and 18 deletions
|
|
@ -71,16 +71,21 @@ class RedisStorageDriver implements StorageDriver
|
|||
return "tenants:{$hash}";
|
||||
}, $uuids);
|
||||
|
||||
// Apparently, the PREFIX is applied to all functions except scan()
|
||||
$redis_prefix = $this->redis->getOption($this->redis->client()::OPT_PREFIX);
|
||||
$hashes = $hashes ?: $this->redis->scan(null, $redis_prefix.'tenants:*');
|
||||
|
||||
return array_map(function ($tenant) use ($redis_prefix) {
|
||||
// Left strip $redis_prefix from $tenant
|
||||
if (substr($tenant, 0, strlen($redis_prefix)) == $redis_prefix) {
|
||||
$tenant = substr($tenant, strlen($redis_prefix));
|
||||
if (! $hashes) {
|
||||
// Apparently, the PREFIX is applied to all functions except scan().
|
||||
// Therefore, if the `tenancy` Redis connection has a prefix set
|
||||
// (and PhpRedis is used), prepend the prefix to the search.
|
||||
$redis_prefix = '';
|
||||
if (config('database.redis.client') === 'phpredis') {
|
||||
$redis_prefix = $this->redis->getOption($this->redis->client()::OPT_PREFIX);
|
||||
}
|
||||
|
||||
$hashes = array_map(function ($hash) use ($redis_prefix) {
|
||||
// Left strip $redis_prefix from $hash
|
||||
return substr($hash, strlen($redis_prefix));
|
||||
}, $this->redis->scan(null, $redis_prefix.'tenants:*'));
|
||||
}
|
||||
|
||||
return array_map(function ($tenant) {
|
||||
return $this->redis->hgetall($tenant);
|
||||
}, $hashes);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue