コード例 #1
0
 /**
  * Returns the wrapped Redis client instance.
  *
  * This method is called from AbstractRedisWrapper, who uses it to call the desired method directly
  * on the wrapped redis, rather than using call_user_func().
  * The command and key are passed into the method to allow for some logic within the implementations
  * of this method.
  *
  * @param string $command the current command
  * @param string|null $key the current key if available, null otherwise. Commands that operate on
  * multiple keys will pass their keys as a comma separated string.
  * @throws Exception when an error happens during connecting
  * @return Redis
  */
 protected function getWrappedRedis($command, $key = null)
 {
     // if we don't have a client yet, we never connected, so let's do it now
     if (!$this->client) {
         // gotta make sure the app actually tried to connect first
         if (!$this->connectWasCalled) {
             throw new Exception('call connect() or pconnect() first');
         }
         if (!($this->persistent ? $this->conn->pconnect($this->host, $this->port, $this->timeout) : $this->conn->connect($this->host, $this->port, $this->timeout))) {
             throw new Exception('could not connect to ' . $this->conn->getUniqueId() . ' params: ' . (!empty($this->host) ? $this->host . ':' . $this->port : 'none'));
         }
         $this->client = $this->conn->getClient();
     }
     return $this->client;
 }
コード例 #2
0
 /**
  * @param Connection $connection The connection to wrap
  * @param string $logFile The name of the file to log the commands to
  * @param \Psr\Log\LoggerInterface $log
  */
 public function __construct(Connection $connection, $logFile, LoggerInterface $log = null)
 {
     $this->connection = $connection;
     $this->client = $connection->getClient();
     $this->logFile = $logFile;
     if ($log === null) {
         $log = new NullLog();
     }
     $this->log = $log;
 }
コード例 #3
0
ファイル: TryCatchWrapper.php プロジェクト: plista/core-redis
 /**
  * @param Connection $connection The connection to catch exceptions for
  * @param ExceptionHandler $handler The error handler which is called if any exception happens
  * @param LoggerInterface $log The logger to which all the exceptions are logged
  */
 function __construct(Connection $connection, ExceptionHandler $handler = null, LoggerInterface $log = null)
 {
     $this->connection = $connection;
     $this->client = $connection->getClient();
     $this->exceptionHandler = $handler;
     $this->defaultHandlerStrategy = ExceptionStrategy::DISCARD();
     if ($log === null) {
         $log = new NullLog();
     }
     $this->log = $log;
 }
コード例 #4
0
ファイル: BufferWrapper.php プロジェクト: plista/core-redis
 /**
  * @param Connection $connection
  */
 public function __construct(Connection $connection)
 {
     $this->connection = $connection;
     $this->redis = $connection->getClient();
 }
コード例 #5
0
 /**
  * @param Connection $conn the wrapped redis connection
  * @param Logger $logger optional, a logger to log the invalid calls to
  */
 public function __construct(Connection $conn, LoggerInterface $logger = null)
 {
     $this->conn = $conn;
     $this->redis = $conn->getClient();
     $this->logger = $logger;
 }
コード例 #6
0
 public function __construct(Connection $conn, Time $time = null)
 {
     $this->connection = $conn;
     $this->redis = $this->connection->getClient();
     $this->time = $time ?: new SystemTime();
 }
コード例 #7
0
 /**
  * @param Connection $conn Connection of the wrapped instance
  */
 public function __construct(Connection $conn)
 {
     $this->connection = $conn;
     $this->client = $conn->getClient();
 }
コード例 #8
0
 /**
  * Test getting the redis interface implementation
  */
 public function testGetClient()
 {
     $this->assertInstanceOf(Redis::class, $this->redis->getClient());
 }