1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-13 01:44:04 +00:00

Fix Redis scan for predis, make phpunit use multiple configs (e.g. different Redis drivers)

This commit is contained in:
Samuel Štancl 2019-08-04 20:04:25 +02:00
parent fe6ce82045
commit 0dc8c80a02
6 changed files with 37 additions and 13 deletions

View file

@ -82,17 +82,21 @@ class RedisStorageDriver implements StorageDriver
}, $uuids);
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 = '';
// Prefix is applied to all functions except scan().
// This code applies the correct prefix manually.
$redis_prefix = config('database.redis.options.prefix');
if (config('database.redis.client') === 'phpredis') {
$redis_prefix = $this->redis->getOption($this->redis->client()::OPT_PREFIX);
$redis_prefix = $this->redis->getOption($this->redis->client()::OPT_PREFIX) ?? $redis_prefix;
$all_keys = $this->redis->scan(null, $redis_prefix . 'tenants:*');
} else {
$all_keys = $this->redis->scan(null, 'MATCH', $redis_prefix . 'tenants:*')[1];
}
$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:*'));
$hashes = array_map(function ($key) use ($redis_prefix) {
// Left strip $redis_prefix from $key
return substr($key, strlen($redis_prefix));
}, $all_keys);
}
return array_map(function ($tenant) {