Sindbad~EG File Manager
<?php
namespace App\Orm;
use App\Entity\Redis\RedisEntityInterface;
use Predis\ClientInterface;
use Predis\Pipeline\Pipeline;
class RedisEntityManager
{
/**
* @var ClientInterface
*/
private $redis;
public function __construct(ClientInterface $redis){
$this->redis = $redis;
}
public function getPipeline() : Pipeline {
return $this->redis->pipeline();
}
public function executePipeline(Pipeline $pipe) : ?array {
return $pipe->execute();
}
public function persist(RedisEntityInterface $object, ?Pipeline $pipe = null) : bool {
$this->remove($object);
foreach(get_class_methods($object) as $k => $method) {
if (strpos($method, 'set') === 0) {
$redisFieldKey = lcfirst(str_replace('set', '', $method));
$getter = str_replace('set', 'get', $method);
if(!is_null($pipe)){
$pipe->hset($object->getKey(), $redisFieldKey, $object->$getter());
} else {
$r = $this->redis->hset($object->getKey(), $redisFieldKey, $object->$getter());
}
}
}
return true;
}
public function remove(RedisEntityInterface $object, bool $strict = false, ?Pipeline $pipe = null) : bool {
if($strict && ! $this->redis->exists($object->getKey())){
return false;
}
$this->redis->del($object->getKey());
if(!is_null($pipe)){
$pipe->del($object->getKey());
} else {
$this->redis->del($object->getKey());
}
return true;
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists