You've already forked Traefik-Redis-Api
Nothing to see here, move along
This commit is contained in:
@@ -41,66 +41,6 @@ class RedisClient
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $data
|
||||
* @param EntityEnum $entity
|
||||
* @param ProtocolEnum $type
|
||||
* @return void
|
||||
*/
|
||||
public static function patchEntity(
|
||||
string $name,
|
||||
array $data,
|
||||
EntityEnum $entity,
|
||||
ProtocolEnum $type = ProtocolEnum::HTTP
|
||||
): void {
|
||||
$collection = self::flattenToDotArray($data);
|
||||
|
||||
$checkKey = 'traefik/' . $type->getValue() . '/' . $entity->getValue() . "/$name";
|
||||
|
||||
$keys = Redis::keys($checkKey . '/*');
|
||||
if (empty($keys)) {
|
||||
throw new \InvalidArgumentException("The key $checkKey does not exist.");
|
||||
}
|
||||
|
||||
$cleanedUpKeys = [];
|
||||
|
||||
foreach ($collection as $key => $value) {
|
||||
// regex if key matches [key].[digit]
|
||||
if (preg_match('/\.[0-9]+$/', $key)) {
|
||||
$arrayKey = preg_replace('/\.[0-9]+$/', '', $key);
|
||||
|
||||
if (in_array($arrayKey, $cleanedUpKeys)) {
|
||||
$redisKey = 'traefik/' .
|
||||
$type->getValue() .
|
||||
'/' .
|
||||
$entity->getValue() .
|
||||
"/$name/" .
|
||||
str_replace('.', '/', $key);
|
||||
|
||||
Redis::set($redisKey, $value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// key is an array, delete keys under array
|
||||
$arrayKeys = Redis::keys($checkKey . '/' . str_replace('.', '/', $arrayKey) . '/*');
|
||||
foreach ($arrayKeys as $k) {
|
||||
Redis::del($k);
|
||||
}
|
||||
|
||||
$cleanedUpKeys[] = $arrayKey;
|
||||
}
|
||||
|
||||
$redisKey = 'traefik/' .
|
||||
$type->getValue() . '/' . $entity->getValue() .
|
||||
"/$name/" .
|
||||
str_replace('.', '/', $key);
|
||||
|
||||
Redis::set($redisKey, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param EntityEnum $entity
|
||||
|
||||
Reference in New Issue
Block a user