getConnection() public method

public getConnection ( )
コード例 #1
0
ファイル: AMQHandler.php プロジェクト: bcrazvan/MateCat
 /**
  * Lazy connection
  *
  * Get the connection to Redis server and return it
  *
  * @throws \Predis\Connection\ConnectionException
  */
 public function getRedisClient()
 {
     if (empty($this->redisHandler)) {
         $this->redisHandler = new RedisHandler();
     }
     return $this->redisHandler->getConnection();
 }
コード例 #2
0
ファイル: RedisCache.php プロジェクト: vaidasif/symfony-force
 public function flushNamespacedKeys()
 {
     $params = $this->redis->getConnection()->getParameters();
     // redis cli connection string
     $conn = sprintf("redis-cli -h %s -p %s -n %s --raw", $params->host, $params->port, $params->database);
     // remove namespaced keys only
     $proc = new Process(sprintf("%s KEYS '*%s*' | xargs --delim='\\n' %s DEL", $conn, $this->ns, $conn));
     $proc->run();
     return $proc->getOutput();
 }
コード例 #3
0
    protected function getParametersAndOptions(Client $client)
    {
        $parameters = $client->getConnection()->getParameters();
        $options = $client->getOptions();

        return array($parameters, $options);
    }
コード例 #4
0
ファイル: RedisDriver.php プロジェクト: andreyors/orm
 /**
  * Scan key-value indices and return the value of all matching keys
  *
  * @param string $key
  *
  * @return string[]
  */
 public function scan($key)
 {
     $cursor = 0;
     $results = [];
     $connection = $this->client->getConnection();
     do {
         if ($connection instanceof ReplicationInterface) {
             /** @var NodeConnectionInterface[] $slaves */
             $slaves = $connection->getSlaves();
             if (count($slaves) == 1) {
                 $slave = $slaves[0];
             } elseif ($slaves) {
                 $slave = $slaves[rand(0, count($slaves) - 1)];
             } else {
                 $slave = $connection->getMaster();
             }
             $cmd = new KeyScan();
             $cmd->setArguments([$cursor, 'MATCH', $key]);
             $set = $slave->executeCommand($cmd);
         } elseif ($connection instanceof PredisCluster) {
             $iterator = $connection->getIterator();
             /** @var NodeConnectionInterface $node */
             $node = $iterator->current();
             $cmd = new KeyScan();
             $cmd->setArguments([$cursor, 'MATCH', $key]);
             $set = $node->executeCommand($cmd);
         } else {
             $set = $this->clientCmd('scan', [$cursor, ['MATCH' => $key]]);
         }
         $cursor = $set[0];
         $results = array_merge($results, $set[1]);
     } while ($cursor != 0);
     return $results;
 }
コード例 #5
0
ファイル: PubSubContext.php プロジェクト: kailIII/pos-erp
 /**
  * Checks if the passed client instance satisfies the required conditions
  * needed to initialize a Publish / Subscribe context.
  *
  * @param Client Client instance used by the context.
  */
 private function checkCapabilities(Client $client)
 {
     if (Helpers::isCluster($client->getConnection())) {
         throw new NotSupportedException('Cannot initialize a PUB/SUB context over a cluster of connections');
     }
     $commands = array('publish', 'subscribe', 'unsubscribe', 'psubscribe', 'punsubscribe');
     if ($client->getProfile()->supportsCommands($commands) === false) {
         throw new NotSupportedException('The current profile does not support PUB/SUB related commands');
     }
 }
コード例 #6
0
ファイル: RedisDriver.php プロジェクト: bravo3/orm
 /**
  * Start listening to subscribed channels of the Redis PubSub mechanism.
  * Add a callback to a particular subscription channel.
  *
  * @param callable $callback
  * @return void
  */
 public function listenToPubSub(callable $callback)
 {
     while (1) {
         $command = RawCommand::create('PSUBSCRIBE', sprintf('%s-%s', $this->pubsub_channel_prefix, '*'));
         $this->client->executeCommand($command);
         if ($this->client->getConnection() instanceof MasterSlaveReplication) {
             $payload = $this->client->getConnection()->getConnection($command)->read();
         } else {
             $payload = $this->client->getConnection()->read();
         }
         $channel = ltrim($payload[2], sprintf('%s%s', $this->pubsub_channel_prefix, '-'));
         $message = base64_decode($payload[3]);
         call_user_func($callback, ['channel' => $channel, 'message' => $message]);
     }
 }
コード例 #7
0
ファイル: PipelineContext.php プロジェクト: kailIII/pos-erp
 /**
  * Returns a pipeline executor depending on the kind of the underlying
  * connection and the passed options.
  *
  * @param Client Client instance used by the context.
  * @param array Options for the context initialization.
  * @return IPipelineExecutor
  */
 protected function createExecutor(Client $client, array $options)
 {
     if (!$options) {
         return new StandardExecutor();
     }
     if (isset($options['executor'])) {
         $executor = $options['executor'];
         if (!$executor instanceof IPipelineExecutor) {
             throw new \InvalidArgumentException('The executor option accepts only instances ' . 'of Predis\\Pipeline\\IPipelineExecutor');
         }
         return $executor;
     }
     if (isset($options['safe']) && $options['safe'] == true) {
         $isCluster = Helpers::isCluster($client->getConnection());
         return $isCluster ? new SafeClusterExecutor() : new SafeExecutor();
     }
     return new StandardExecutor();
 }
コード例 #8
0
ファイル: MultiExecContext.php プロジェクト: kailIII/pos-erp
 /**
  * Checks if the passed client instance satisfies the required conditions
  * needed to initialize a transaction context.
  *
  * @param Client Client instance used by the context.
  */
 private function checkCapabilities(Client $client)
 {
     if (Helpers::isCluster($client->getConnection())) {
         throw new NotSupportedException('Cannot initialize a MULTI/EXEC context over a cluster of connections');
     }
     $profile = $client->getProfile();
     if ($profile->supportsCommands(array('multi', 'exec', 'discard')) === false) {
         throw new NotSupportedException('The current profile does not support MULTI, EXEC and DISCARD');
     }
     $this->canWatch = $profile->supportsCommands(array('watch', 'unwatch'));
 }
コード例 #9
0
ファイル: ClientTest.php プロジェクト: rodrigopbel/ong
 /**
  * @group disconnected
  */
 public function testCreateClientWithConnectionFromAggregatedConnection()
 {
     $client = new Client(array('tcp://host1?alias=node01', 'tcp://host2?alias=node02'), array('prefix' => 'pfx:'));
     $this->assertInstanceOf('Predis\\Connection\\ClusterConnectionInterface', $cluster = $client->getConnection());
     $this->assertInstanceOf('Predis\\Connection\\SingleConnectionInterface', $node01 = $client->getConnectionById('node01'));
     $this->assertInstanceOf('Predis\\Connection\\SingleConnectionInterface', $node02 = $client->getConnectionById('node02'));
     $clientNode02 = $client->getClientFor('node02');
     $this->assertInstanceOf('Predis\\Client', $clientNode02);
     $this->assertSame($node02, $clientNode02->getConnection());
     $this->assertSame($client->getOptions(), $clientNode02->getOptions());
 }
コード例 #10
0
ファイル: ClientTest.php プロジェクト: rubensayshi/predis
 /**
  * @group disconnected
  * @expectedException Predis\NotSupportedException
  * @expectedExceptionMessage Retrieving connections by alias is supported only with aggregated connections
  */
 public function testGetConnectionWithAliasWorksOnlyWithCluster()
 {
     $client = new Client();
     $client->getConnection('node01');
 }
コード例 #11
0
ファイル: Predis.php プロジェクト: silky/littlesis
 /**
  * Checks if the passed client instance satisfies the required conditions
  * needed to initialize a monitor context.
  *
  * @param Client Client instance used by the context.
  */
 private function checkCapabilities(Client $client)
 {
     if (Helpers::isCluster($client->getConnection())) {
         throw new ClientException('Cannot initialize a monitor context over a cluster of connections');
     }
     if ($client->getProfile()->supportsCommand('monitor') === false) {
         throw new ClientException('The current profile does not support the MONITOR command');
     }
 }