当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::getConnection方法代码示例

本文整理汇总了PHP中Predis\Client::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getConnection方法的具体用法?PHP Client::getConnection怎么用?PHP Client::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Predis\Client的用法示例。


在下文中一共展示了Client::getConnection方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getRedisClient

 /**
  * 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();
 }
开发者ID:bcrazvan,项目名称:MateCat,代码行数:14,代码来源:AMQHandler.php

示例2: flushNamespacedKeys

 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();
 }
开发者ID:vaidasif,项目名称:symfony-force,代码行数:10,代码来源:RedisCache.php

示例3: getParametersAndOptions

    protected function getParametersAndOptions(Client $client)
    {
        $parameters = $client->getConnection()->getParameters();
        $options = $client->getOptions();

        return array($parameters, $options);
    }
开发者ID:nrk,项目名称:PredisServiceProvider,代码行数:7,代码来源:ProviderTestCase.php

示例4: scan

 /**
  * 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;
 }
开发者ID:andreyors,项目名称:orm,代码行数:41,代码来源:RedisDriver.php

示例5: checkCapabilities

 /**
  * 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');
     }
 }
开发者ID:kailIII,项目名称:pos-erp,代码行数:16,代码来源:PubSubContext.php

示例6: listenToPubSub

 /**
  * 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]);
     }
 }
开发者ID:bravo3,项目名称:orm,代码行数:22,代码来源:RedisDriver.php

示例7: createExecutor

 /**
  * 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();
 }
开发者ID:kailIII,项目名称:pos-erp,代码行数:26,代码来源:PipelineContext.php

示例8: checkCapabilities

 /**
  * 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'));
 }
开发者ID:kailIII,项目名称:pos-erp,代码行数:17,代码来源:MultiExecContext.php

示例9: testCreateClientWithConnectionFromAggregatedConnection

 /**
  * @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());
 }
开发者ID:rodrigopbel,项目名称:ong,代码行数:14,代码来源:ClientTest.php

示例10: testGetConnectionWithAliasWorksOnlyWithCluster

 /**
  * @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');
 }
开发者ID:rubensayshi,项目名称:predis,代码行数:10,代码来源:ClientTest.php

示例11: checkCapabilities

 /**
  * 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');
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:15,代码来源:Predis.php


注:本文中的Predis\Client::getConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。