"Fossies" - the Fresh Open Source Software Archive

Member "serendipity/bundled-libs/voku/simple-cache/src/voku/cache/AdapterPredis.php" (20 Nov 2022, 1701 Bytes) of package /linux/www/serendipity-2.4.0.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AdapterPredis.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.3.5_vs_2.4.0.

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 namespace voku\cache;
    6 
    7 use Predis\Client;
    8 
    9 /**
   10  * AdapterPredis: Memcached-adapter
   11  */
   12 class AdapterPredis implements iAdapter
   13 {
   14     /**
   15      * @var bool
   16      */
   17     public $installed = false;
   18 
   19     /**
   20      * @var Client
   21      */
   22     private $client;
   23 
   24     /**
   25      * @param Client|null $client
   26      */
   27     public function __construct($client = null)
   28     {
   29         if ($client instanceof Client) {
   30             $this->setPredisClient($client);
   31         }
   32     }
   33 
   34     /**
   35      * @param Client $client
   36      *
   37      * @return void
   38      */
   39     public function setPredisClient(Client $client)
   40     {
   41         $this->installed = true;
   42         $this->client = $client;
   43     }
   44 
   45     /**
   46      * {@inheritdoc}
   47      */
   48     public function exists(string $key): bool
   49     {
   50         return (bool) $this->client->exists($key);
   51     }
   52 
   53     /**
   54      * {@inheritdoc}
   55      */
   56     public function get(string $key)
   57     {
   58         return $this->client->get($key);
   59     }
   60 
   61     /**
   62      * {@inheritdoc}
   63      */
   64     public function installed(): bool
   65     {
   66         return $this->installed;
   67     }
   68 
   69     /**
   70      * {@inheritdoc}
   71      */
   72     public function remove(string $key): bool
   73     {
   74         return (bool) $this->client->del($key);
   75     }
   76 
   77     /**
   78      * {@inheritdoc}
   79      */
   80     public function removeAll(): bool
   81     {
   82         return $this->client->flushall();
   83     }
   84 
   85     /**
   86      * {@inheritdoc}
   87      */
   88     public function set(string $key, $value): bool
   89     {
   90         return $this->client->set($key, $value);
   91     }
   92 
   93     /**
   94      * {@inheritdoc}
   95      */
   96     public function setExpired(string $key, $value, int $ttl = 0): bool
   97     {
   98         return (bool) $this->client->setex($key, $ttl, $value);
   99     }
  100 }