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


PHP Client::connect方法代码示例

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


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

示例1: __construct

 /**
  * @param $sourceConfig connection URI string (tcp://10.0.0.1:6379)
  * @param $destinationConfig connection URI string (tcp://10.0.0.1:6379)
  * @throws Predis\Connection\ConnectionException
  */
 public function __construct($sourceConfig, $destinationConfig)
 {
     $this->source = new Client($sourceConfig);
     $this->destination = new Client($destinationConfig);
     $this->source->connect();
     $this->destination->connect();
 }
开发者ID:becquerel,项目名称:redis-copy,代码行数:12,代码来源:RedisCopy.php

示例2: fork

 public function fork()
 {
     $id = pcntl_fork();
     if (!$id) {
         $this->redis->disconnect();
         $this->redis->connect();
     }
     return $id;
 }
开发者ID:halaei,项目名称:redis-hyper-queue,代码行数:9,代码来源:IntegrationTestCase.php

示例3: connect

 /**
  * Creates a connect to Redis or Sentinel using the Predis\Client object.  It proxies the connecting and converts
  * specific client exceptions to more generic adapted ones in PSRedis
  *
  * @throws \PSRedis\Exception\ConnectionError
  */
 public function connect()
 {
     try {
         $this->predisClient = $this->predisClientFactory->createClient($this->clientType, $this->getPredisClientParameters());
         $this->predisClient->connect();
         $this->isConnected = $this->predisClient->isConnected();
     } catch (ConnectionException $e) {
         throw new ConnectionError($e->getMessage());
     }
 }
开发者ID:hemingw,项目名称:PSRedis,代码行数:16,代码来源:PredisClientAdapter.php

示例4: init

 public function init()
 {
     $settings = Config::get('ajumamoro:broker');
     unset($settings['driver']);
     $this->redis = new \Predis\Client($settings);
     try {
         $this->redis->connect();
     } catch (\Predis\CommunicationException $ex) {
         throw new BrokerConnectionException("Failed to connect to redis broker: {$ex->getMessage()}");
     }
 }
开发者ID:ekowabaka,项目名称:ajumamoro,代码行数:11,代码来源:RedisBroker.php

示例5: checkConnection

 /**
  * @return bool
  */
 public function checkConnection()
 {
     if (!$this->predis->isConnected()) {
         try {
             $this->predis->connect();
             return true;
         } catch (ConnectionException $e) {
             return false;
         }
     }
     return true;
 }
开发者ID:gerifield,项目名称:little-red-queue,代码行数:15,代码来源:LittleRedQueue.php

示例6: list

 function __construct($url)
 {
     try {
         list($user, $passwd, $host, $port, $db) = self::parseRedisUrl($url);
         $this->_redis = new Client(array('host' => $host, 'port' => $port));
     } catch (\Exception $e) {
         throw new RedisBundleException($e);
     }
     try {
         $this->_redis->connect();
         $this->_redis->select($db);
     } catch (\Predis\Connection\ConnectionException $e) {
         throw new RedisBundleException($e);
     }
 }
开发者ID:haberberger,项目名称:redisstoragebundle,代码行数:15,代码来源:RedisStorage.php

示例7: testDispatcherLoopAgainstRedisServer

 /**
  * @group connected
  */
 public function testDispatcherLoopAgainstRedisServer()
 {
     $parameters = array('host' => REDIS_SERVER_HOST, 'port' => REDIS_SERVER_PORT, 'database' => REDIS_SERVER_DBNUM, 'read_write_timeout' => 2);
     $producer = new Client($parameters, REDIS_SERVER_VERSION);
     $producer->connect();
     $consumer = new Client($parameters, REDIS_SERVER_VERSION);
     $consumer->connect();
     $dispatcher = new DispatcherLoop($consumer);
     $function01 = $this->getMock('stdClass', array('__invoke'));
     $function01->expects($this->exactly(2))->method('__invoke')->with($this->logicalOr($this->equalTo('01:argument'), $this->equalTo('01:quit')))->will($this->returnCallback(function ($arg) use($dispatcher) {
         if ($arg === '01:quit') {
             $dispatcher->stop();
         }
     }));
     $function02 = $this->getMock('stdClass', array('__invoke'));
     $function02->expects($this->once())->method('__invoke')->with('02:argument');
     $function03 = $this->getMock('stdClass', array('__invoke'));
     $function03->expects($this->never())->method('__invoke');
     $dispatcher->attachCallback('function:01', $function01);
     $dispatcher->attachCallback('function:02', $function02);
     $dispatcher->attachCallback('function:03', $function03);
     $producer->publish('function:01', '01:argument');
     $producer->publish('function:02', '02:argument');
     $producer->publish('function:01', '01:quit');
     $dispatcher->run();
     $this->assertTrue($consumer->ping());
 }
开发者ID:keneanung,项目名称:gw2spidy,代码行数:30,代码来源:DispatcherLoopTest.php

示例8: testHandleLogWithGoodMessageNotImplementingJobInterface

 public function testHandleLogWithGoodMessageNotImplementingJobInterface()
 {
     $worker = new WorkerPresence();
     $worker->setMemory(12345);
     $frame = new Frame('MESSAGE', array('delivery_tag' => 'delivery-' . mt_rand()), $worker->toJson());
     $loop = LoopFactory::create();
     $options = array('eventloop' => $loop, 'on_error' => array($this, 'throwRedisError'));
     $redisSync = new PredisSync('tcp://127.0.0.1:6379');
     $redisSync->connect();
     $resolver = $this->getResolver();
     $resolver->expects($this->once())->method('ack');
     $done = false;
     $phpunit = $this;
     $redis = new PredisAsync('tcp://127.0.0.1:6379', $options);
     $redis->connect(function () use($resolver, $phpunit, $redis, $frame, $redisSync, &$done, $worker) {
         $component = new LogBuilderComponent();
         $component->handleLog($redis, $phpunit->getLogger(), $frame, $resolver)->then(function ($hashId) use($phpunit, $redis, $redisSync, &$done, $worker) {
             $redis->disconnect();
             $phpunit->assertEquals($worker->toJson(), $redisSync->get($hashId));
             $phpunit->assertTrue($redisSync->sismember('garbages', $hashId));
             $done = true;
         });
     });
     $loop->run();
     $this->assertTrue($done);
 }
开发者ID:gloubster,项目名称:server,代码行数:26,代码来源:LogBuilderComponentTest.php

示例9: getClient

 /**
  * Returns a new client instance.
  *
  * @return Client
  */
 protected function getClient()
 {
     $parameters = array('host' => REDIS_SERVER_HOST, 'port' => REDIS_SERVER_PORT, 'iterable_multibulk' => true, 'read_write_timeout' => 2);
     $client = new Client($parameters, REDIS_SERVER_VERSION);
     $client->connect();
     $client->select(REDIS_SERVER_DBNUM);
     $client->flushdb();
     return $client;
 }
开发者ID:keneanung,项目名称:gw2spidy,代码行数:14,代码来源:MultiBulkResponseTupleTest.php

示例10: __construct

 /**
  * ### Tries to connect to the configured redis database
  *
  * RedisCache constructor.
  */
 public function __construct()
 {
     $client = new Client(['scheme' => 'tcp', 'host' => Config::get('cache', 'redis_server.host'), 'port' => Config::get('cache', 'redis_server.port'), 'database' => Config::get('cache', 'redis_server.database')]);
     try {
         $client->connect();
     } catch (\Exception $e) {
         throw new RedisException('Connection to redis server failed. Please check your settings.');
     }
     $this->conn = $client;
 }
开发者ID:JanFoerste,项目名称:blivy-website,代码行数:15,代码来源:RedisCache.php

示例11: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $client = new Client();
     try {
         $client->connect();
         $client->disconnect();
         self::$supported = true;
     } catch (ConnectionException $e) {
         self::$supported = false;
     }
 }
开发者ID:kormik,项目名称:manager,代码行数:12,代码来源:PredisStoreGeneratorTest.php

示例12: setUp

 public function setUp()
 {
     // connect to a redis daemon
     $predis = new Predis(array('host' => $_ENV['redis_host'], 'port' => $_ENV['redis_port']));
     // set it
     $this->storage = new Redis($predis, 'test_user_token', 'test_user_state');
     try {
         $predis->connect();
     } catch (\Predis\Connection\ConnectionException $e) {
         $this->markTestSkipped('No redis instance available: ' . $e->getMessage());
     }
 }
开发者ID:Flesh192,项目名称:magento,代码行数:12,代码来源:RedisTest.php

示例13: setUp

 public function setUp()
 {
     if (!class_exists('Predis\\Client')) {
         $this->markTestSkipped('The ' . __CLASS__ . ' requires Predis to be available');
     }
     try {
         $client = new Client();
         $client->connect();
         $client->flushdb();
     } catch (ConnectionException $e) {
         $this->markTestSkipped('The ' . __CLASS__ . ' requires the use of a Redis Server');
     }
     $this->storage = new RedisStorage($client);
 }
开发者ID:battlerattle,项目名称:shuffle-bag,代码行数:14,代码来源:RedisStorageTest.php

示例14: getClient

 /**
  * Returns a new client instance.
  *
  * @param Boolean $connect Flush selected database before returning the client.
  * @return Client
  */
 protected function getClient($flushdb = true)
 {
     $profile = $this->getProfile();
     if (!$profile->supportsCommand($id = $this->getExpectedId())) {
         $this->markTestSkipped("The profile {$profile->getVersion()} does not support command {$id}");
     }
     $parameters = array('host' => REDIS_SERVER_HOST, 'port' => REDIS_SERVER_PORT);
     $options = array('profile' => $profile);
     $client = new Client($parameters, $options);
     $client->connect();
     $client->select(REDIS_SERVER_DBNUM);
     if ($flushdb) {
         $client->flushdb();
     }
     return $client;
 }
开发者ID:surjit,项目名称:node-redis-php-chat-app,代码行数:22,代码来源:CommandTestCase.php

示例15: test_published_messages_fire_event_listeners_when_rechech_called

 public function test_published_messages_fire_event_listeners_when_rechech_called()
 {
     $redis = new Client();
     $pubsub = new RedisPubSub($redis);
     try {
         $redis->connect();
     } catch (ConnectionException $e) {
         $this->markTestSkipped("Test skipped because no Redis server is running on default ports");
     }
     $value = null;
     $pubsub->on('foo', function ($data) use(&$value) {
         $value = $data;
     });
     $pubsub->publish('foo', 'bar');
     $pubsub->recheck('foo');
     $this->assertEquals('bar', $value);
 }
开发者ID:adamnicholson,项目名称:kyew,代码行数:17,代码来源:RedisPubSubTest.php


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