Skip to content

Instantly share code, notes, and snippets.

@Nex-Otaku
Created April 15, 2020 14:36
Show Gist options
  • Save Nex-Otaku/5fa990c3f01476672d6388ff58dcb508 to your computer and use it in GitHub Desktop.
Save Nex-Otaku/5fa990c3f01476672d6388ff58dcb508 to your computer and use it in GitHub Desktop.
<?php
namespace App\Redis;
use Spiral\Config\ConfiguratorInterface;
class RedisConnection
{
/** @var string */
private $connectionId;
/** @var string */
private $host;
/** @var int */
private $port;
/** @var int */
private $database;
/**
* RedisConnection constructor.
* @param ConfiguratorInterface $configurator
* @param string $connectionId
*/
public function __construct(
ConfiguratorInterface $configurator,
string $connectionId
)
{
$this->connectionId = $connectionId;
$connections = $configurator->getConfig('redis')['connections'];
if (!array_key_exists($connectionId, $connections)) {
throw new \LogicException("Не определена конфигурация для Redis: {$connectionId}");
}
$config = $connections[$connectionId];
$this->host = $config['host'];
$this->port = (int)$config['port'];
$this->database = (int)$config['database'];
}
/**
* @param string $key
* @return string|null
*/
public function get(string $key): ?string
{
throw new \LogicException('Redis get not implemented');
}
/**
* @param string $key
* @param string $value
* @param int $expireSeconds
*/
public function set(string $key, string $value, int $expireSeconds = 0): void
{
throw new \LogicException('Redis set not implemented');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment