php Predis-Profile-ServerProfile类(方法)实例源码

下面列出了php Predis-Profile-ServerProfile 类(方法)源码代码实例,从而了解它的用法。

作者:rodrigopbe    项目:on   
/**
  * {@inheritdoc}
  */
 public function getDefault(ClientOptionsInterface $options)
 {
     $profile = ServerProfile::getDefault();
     if (isset($options->prefix)) {
         $profile->setProcessor($options->prefix);
     }
     return $profile;
 }

作者:GeorgeBroadle    项目:caffeine-vendo   
/**
  * Returns a list of queued command instances.
  *
  * @return SplQueue
  */
 protected function getCommandsQueue()
 {
     $profile = ServerProfile::getDevelopment();
     $pipeline = new SplQueue();
     $pipeline->enqueue($profile->createCommand('ping'));
     $pipeline->enqueue($profile->createCommand('ping'));
     $pipeline->enqueue($profile->createCommand('ping'));
     return $pipeline;
 }

作者:kchhainaron    项目:chantuch   
/**
  * @group disconnected
  */
 public function testConstructorOpensContext()
 {
     $cmdMonitor = ServerProfile::getDefault()->createCommand('monitor');
     $connection = $this->getMock('Predis\\Connection\\SingleConnectionInterface');
     $client = $this->getMock('Predis\\Client', array('createCommand', 'executeCommand'), array($connection));
     $client->expects($this->once())->method('createCommand')->with('monitor', array())->will($this->returnValue($cmdMonitor));
     $client->expects($this->once())->method('executeCommand')->with($cmdMonitor);
     $monitor = new MonitorContext($client);
 }

作者:kchhainaron    项目:chantuch   
/**
  * @group disconnected
  */
 public function testExecuteCommandDoesNotSendCommandsWithoutExecute()
 {
     $profile = ServerProfile::getDefault();
     $executor = $this->getMock('Predis\\Pipeline\\PipelineExecutorInterface');
     $executor->expects($this->never())->method('executor');
     $pipeline = new PipelineContext(new Client(), $executor);
     $pipeline->executeCommand($profile->createCommand('echo', array('one')));
     $pipeline->executeCommand($profile->createCommand('echo', array('two')));
     $pipeline->executeCommand($profile->createCommand('echo', array('three')));
 }

作者:shinichi8    项目:laravel4dem   
/**
  * @group disconnected
  */
 public function testClosingContextWithFalseSendsUnsubscriptions()
 {
     $profile = ServerProfile::get(REDIS_SERVER_VERSION);
     $classUnsubscribe = $profile->getCommandClass('unsubscribe');
     $classPunsubscribe = $profile->getCommandClass('punsubscribe');
     $connection = $this->getMock('Predis\\Connection\\SingleConnectionInterface');
     $client = $this->getMock('Predis\\Client', array('disconnect'), array($connection));
     $options = array('subscribe' => 'channel:foo', 'psubscribe' => 'channels:*');
     $pubsub = new PubSubContext($client, $options);
     $connection->expects($this->exactly(2))->method('writeCommand')->with($this->logicalOr($this->isInstanceOf($classUnsubscribe), $this->isInstanceOf($classPunsubscribe)));
     $pubsub->closeContext(false);
 }

作者:ningcaiche    项目:laravel-4.1-quick-start-c   
/**
  * @group disconnected
  */
 public function testSettingCustomCommandHandler()
 {
     $strategy = $this->getHashStrategy();
     $profile = ServerProfile::getDevelopment();
     $callable = $this->getMock('stdClass', array('__invoke'));
     $callable->expects($this->once())->method('__invoke')->with($this->isInstanceOf('Predis\\Command\\CommandInterface'))->will($this->returnValue('key'));
     $strategy->setCommandHandler('get', $callable);
     $command = $profile->createCommand('get', array('key'));
     $this->assertNotNull($strategy->getHash($command));
 }

作者:rubensaysh    项目:predi   
local hashes = {}
for _, key in pairs(KEYS) do
    table.insert(hashes, key)
    table.insert(hashes, redis.call('hgetall', key))
end
return hashes
EOS;
    public function getScript()
    {
        return self::BODY;
    }
}
// ------------------------------------------------------------------------- //
$parameters = array('tcp://127.0.0.1:6379/?alias=master', 'tcp://127.0.0.1:6380/?alias=slave');
$options = array('profile' => function ($options) {
    $profile = ServerProfile::get('2.6');
    $profile->defineCommand('hmgetall', 'HashMultipleGetAll');
    return $profile;
}, 'replication' => function ($options) {
    $replication = new MasterSlaveReplication();
    $replication->setScriptReadOnly(HashMultipleGetAll::BODY);
    return $replication;
});
// ------------------------------------------------------------------------- //
$client = new Predis\Client($parameters, $options);
// Execute the following commands on the master server using redis-cli:
// $ ./redis-cli HMSET metavars foo bar hoge piyo
// $ ./redis-cli HMSET servers master host1 slave host2
$hashes = $client->hmgetall('metavars', 'servers');
$replication = $client->getConnection();
$stillOnSlave = $replication->getCurrent() === $replication->getConnectionById('slave');

作者:tyst    项目:predis-asyn   
/**
  * @group disconnected
  */
 public function testCreatesNewCommandUsingSpecifiedProfile()
 {
     $ping = ServerProfile::getDefault()->createCommand('ping', array());
     $profile = $this->getMock('Predis\\Profile\\ServerProfileInterface');
     $profile->expects($this->once())->method('createCommand')->with('ping', array())->will($this->returnValue($ping));
     $client = new Client(null, array('profile' => $profile));
     $this->assertSame($ping, $client->createCommand('ping', array()));
 }

作者:ningcaiche    项目:laravel-4.1-quick-start-c   
/**
  * @group disconnected
  * @expectedException Predis\NotSupportedException
  * @expectedExceptionMessage Cannot use PING with redis-cluster
  */
 public function testThrowsExceptionOnNonSupportedCommand()
 {
     $ping = ServerProfile::getDefault()->createCommand('ping');
     $cluster = new RedisCluster();
     $cluster->add($this->getMockConnection('tcp://127.0.0.1:6379'));
     $cluster->getConnection($ping);
 }

作者:ningcaiche    项目:laravel-4.1-quick-start-c   
/**
  * Returns a new instance of server profile.
  *
  * @param  string                 $version Redis profile.
  * @return ServerProfileInterface
  */
 protected function getProfile($version = null)
 {
     return ServerProfile::get($version ?: REDIS_SERVER_VERSION);
 }

作者:rubensaysh    项目:predi   
/**
  * {@inheritdoc}
  */
 public function create($parameters, ServerProfileInterface $profile = null)
 {
     if (!$parameters instanceof ConnectionParametersInterface) {
         $parameters = new ConnectionParameters($parameters ?: array());
     }
     $scheme = $parameters->scheme;
     if (!isset($this->schemes[$scheme])) {
         throw new \InvalidArgumentException("Unknown connection scheme: {$scheme}");
     }
     $initializer = $this->schemes[$scheme];
     if (!is_callable($initializer)) {
         $connection = new $initializer($parameters);
         $this->prepareConnection($connection, $profile ?: ServerProfile::getDefault());
         return $connection;
     }
     $connection = call_user_func($initializer, $parameters, $profile);
     if (!$connection instanceof SingleConnectionInterface) {
         throw new \InvalidArgumentException('Objects returned by connection initializers must implement ' . 'Predis\\Connection\\SingleConnectionInterface');
     }
     return $connection;
 }

作者:ningcaiche    项目:laravel-4.1-quick-start-c   
/**
  * @group disconnected
  */
 public function testChainOfProcessors()
 {
     $processor = $this->getMock('Predis\\Command\\Processor\\CommandProcessorInterface');
     $processor->expects($this->exactly(2))->method('process');
     $chain = new ProcessorChain();
     $chain->add($processor);
     $chain->add($processor);
     $profile = ServerProfile::getDefault();
     $profile->setProcessor($chain);
     $profile->createCommand('info');
 }

作者:kchhainaron    项目:chantuch   
/**
  * @group disconnected
  */
 public function testExecuteCommandOnEachNode()
 {
     $ping = ServerProfile::getDefault()->createCommand('ping', array());
     $connection1 = $this->getMock('Predis\\Connection\\SingleConnectionInterface');
     $connection1->expects($this->once())->method('executeCommand')->with($ping)->will($this->returnValue(true));
     $connection2 = $this->getMock('Predis\\Connection\\SingleConnectionInterface');
     $connection2->expects($this->once())->method('executeCommand')->with($ping)->will($this->returnValue(false));
     $cluster = new PredisCluster();
     $cluster->add($connection1);
     $cluster->add($connection2);
     $this->assertSame(array(true, false), $cluster->executeCommandOnNodes($ping));
 }

作者:rodrigopbe    项目:on   
/**
  * @group disconnected
  */
 public function testIterationRewindable()
 {
     $client = $this->getMock('Predis\\Client', array('getProfile', 'lrange'));
     $client->expects($this->any())->method('getProfile')->will($this->returnValue(ServerProfile::getDefault()));
     $client->expects($this->exactly(2))->method('lrange')->with('key:list', 0, 9)->will($this->returnValue(array('item:1', 'item:2')));
     $iterator = new ListKey($client, 'key:list');
     $iterator->rewind();
     $this->assertTrue($iterator->valid());
     $this->assertSame('item:1', $iterator->current());
     $this->assertSame(0, $iterator->key());
     $iterator->rewind();
     $this->assertTrue($iterator->valid());
     $this->assertSame('item:1', $iterator->current());
     $this->assertSame(0, $iterator->key());
     $iterator->next();
     $this->assertTrue($iterator->valid());
     $this->assertSame(1, $iterator->key());
     $this->assertSame('item:2', $iterator->current());
     $iterator->next();
     $this->assertFalse($iterator->valid());
 }

作者:rubensaysh    项目:predi   
/**
  * @group disconnected
  */
 public function testCanSetReadOnlyFlagForEvalScripts()
 {
     $profile = ServerProfile::get('dev');
     $cmdEval = $profile->createCommand('eval', array($script = "return redis.call('info');"));
     $cmdEvalSha = $profile->createCommand('evalsha', array($scriptSHA1 = sha1($script)));
     $master = $this->getMockConnection('tcp://host1?alias=master');
     $master->expects($this->never())->method('executeCommand');
     $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
     $slave1->expects($this->exactly(2))->method('executeCommand')->with($this->logicalOr($cmdEval, $cmdEvalSha));
     $replication = new MasterSlaveReplication();
     $replication->add($master);
     $replication->add($slave1);
     $replication->setScriptReadOnly($script);
     $replication->executeCommand($cmdEval);
     $replication->executeCommand($cmdEvalSha);
 }

作者:nextim    项目:SncRedisBundl   
/**
  * Loads a redis client using predis.
  *
  * @param array            $client    A client configuration
  * @param ContainerBuilder $container A ContainerBuilder instance
  */
 protected function loadPredisClient(array $client, ContainerBuilder $container)
 {
     if (null === $client['options']['cluster']) {
         unset($client['options']['cluster']);
     }
     // predis connection parameters have been renamed in v0.8
     $client['options']['async_connect'] = $client['options']['connection_async'];
     $client['options']['timeout'] = $client['options']['connection_timeout'];
     $client['options']['persistent'] = $client['options']['connection_persistent'];
     $client['options']['exceptions'] = $client['options']['throw_errors'];
     unset($client['options']['connection_async']);
     unset($client['options']['connection_timeout']);
     unset($client['options']['connection_persistent']);
     unset($client['options']['throw_errors']);
     $connectionAliases = array();
     $connectionCount = count($client['dsns']);
     foreach ($client['dsns'] as $i => $dsn) {
         /** @var \Snc\RedisBundle\DependencyInjection\Configuration\RedisDsn $dsn */
         if (!($connectionAlias = $dsn->getAlias())) {
             $connectionAlias = 1 === $connectionCount ? $client['alias'] : $client['alias'] . ($i + 1);
         }
         $connectionAliases[] = $connectionAlias;
         $connection = $client['options'];
         $connection['logging'] = $client['logging'];
         $connection['alias'] = $connectionAlias;
         if (null !== $dsn->getSocket()) {
             $connection['scheme'] = 'unix';
             $connection['path'] = $dsn->getSocket();
         } else {
             $connection['scheme'] = 'tcp';
             $connection['host'] = $dsn->getHost();
             $connection['port'] = $dsn->getPort();
         }
         if (null !== $dsn->getDatabase()) {
             $connection['database'] = $dsn->getDatabase();
         }
         $connection['password'] = $dsn->getPassword();
         $connection['weight'] = $dsn->getWeight();
         $this->loadPredisConnectionParameters($client['alias'], $connection, $container);
     }
     // TODO can be shared between clients?!
     $profileId = sprintf('snc_redis.client.%s_profile', $client['alias']);
     $profileDef = new Definition(get_class(\Predis\Profile\ServerProfile::get($client['options']['profile'])));
     // TODO get_class alternative?
     $profileDef->setPublic(false);
     $profileDef->setScope(ContainerInterface::SCOPE_CONTAINER);
     if (null !== $client['options']['prefix']) {
         $processorId = sprintf('snc_redis.client.%s_processor', $client['alias']);
         $processorDef = new Definition('Predis\\Command\\Processor\\KeyPrefixProcessor');
         $processorDef->setArguments(array($client['options']['prefix']));
         $container->setDefinition($processorId, $processorDef);
         $profileDef->addMethodCall('setProcessor', array(new Reference($processorId)));
     }
     $container->setDefinition($profileId, $profileDef);
     $client['options']['profile'] = new Reference($profileId);
     $optionId = sprintf('snc_redis.client.%s_options', $client['alias']);
     $optionDef = new Definition($container->getParameter('snc_redis.client_options.class'));
     $optionDef->setPublic(false);
     $optionDef->setScope(ContainerInterface::SCOPE_CONTAINER);
     $optionDef->addArgument($client['options']);
     $container->setDefinition($optionId, $optionDef);
     $clientDef = new Definition($container->getParameter('snc_redis.client.class'));
     $clientDef->setScope(ContainerInterface::SCOPE_CONTAINER);
     if (1 === $connectionCount) {
         $clientDef->addArgument(new Reference(sprintf('snc_redis.connection.%s_parameters', $connectionAliases[0])));
     } else {
         $connections = array();
         foreach ($connectionAliases as $alias) {
             $connections[] = new Reference(sprintf('snc_redis.connection.%s_parameters', $alias));
         }
         $clientDef->addArgument($connections);
     }
     $clientDef->addArgument(new Reference($optionId));
     $container->setDefinition(sprintf('snc_redis.%s', $client['alias']), $clientDef);
     $container->setAlias(sprintf('snc_redis.%s_client', $client['alias']), sprintf('snc_redis.%s', $client['alias']));
 }

作者:kchhainaron    项目:chantuch   
/**
  * @group disconnected
  */
 public function testIterationRewindable()
 {
     $client = $this->getMock('Predis\\Client', array('getProfile', 'scan'));
     $client->expects($this->any())->method('getProfile')->will($this->returnValue(ServerProfile::get('2.8')));
     $client->expects($this->exactly(2))->method('scan')->with(0, array())->will($this->returnValue(array(0, array('key:1st', 'key:2nd'))));
     $iterator = new Keyspace($client);
     $iterator->rewind();
     $this->assertTrue($iterator->valid());
     $this->assertSame('key:1st', $iterator->current());
     $this->assertSame(0, $iterator->key());
     $iterator->rewind();
     $this->assertTrue($iterator->valid());
     $this->assertSame('key:1st', $iterator->current());
     $this->assertSame(0, $iterator->key());
     $iterator->next();
     $this->assertTrue($iterator->valid());
     $this->assertSame(1, $iterator->key());
     $this->assertSame('key:2nd', $iterator->current());
     $iterator->next();
     $this->assertFalse($iterator->valid());
 }

作者:Thomv    项目:turbin   
/**
  * @group disconnected
  */
 public function testSetLuaScriptAsReadOperation()
 {
     $strategy = new ReplicationStrategy();
     $profile = ServerProfile::getDevelopment();
     $writeScript = 'redis.call("set", "foo", "bar")';
     $readScript = 'return true';
     $strategy->setScriptReadOnly($readScript, true);
     $cmdEval = $profile->createCommand('EVAL', array($writeScript));
     $cmdEvalSHA = $profile->createCommand('EVALSHA', array(sha1($writeScript)));
     $this->assertFalse($strategy->isReadOperation($cmdEval));
     $this->assertFalse($strategy->isReadOperation($cmdEvalSHA));
     $cmdEval = $profile->createCommand('EVAL', array($readScript));
     $cmdEvalSHA = $profile->createCommand('EVALSHA', array(sha1($readScript)));
     $this->assertTrue($strategy->isReadOperation($cmdEval));
     $this->assertTrue($strategy->isReadOperation($cmdEvalSHA));
 }

作者:tyst    项目:predis-asyn   
/**
  * Returns a new instance of client options.
  *
  * @return ClientOptions
  * @param array $override Override default options.
  */
 protected function getOptions($override = null)
 {
     $options = new ClientOptions(array_merge(array('profile' => ServerProfile::get(REDIS_SERVER_VERSION), 'eventloop' => $this->getEventLoop())), $override ?: array());
     return $options;
 }

作者:surji    项目:node-redis-php-chat-ap   
/**
  * Return the server profile used during the tests.
  *
  * @return ServerProfileInterface
  */
 protected function getProfile()
 {
     return ServerProfile::get(REDIS_SERVER_VERSION);
 }


问题


面经


文章

微信
公众号

扫码关注公众号