예제 #1
0
 protected function get_servers()
 {
     $server = array('alias' => 'Master', 'scheme' => 'tcp');
     foreach (['scheme', 'host', 'port', 'path', 'password', 'database'] as $setting) {
         $constant = sprintf('WP_REDIS_%s', strtoupper($setting));
         if (defined($constant)) {
             $server[$setting] = constant($constant);
         }
     }
     if (defined('WP_REDIS_CLUSTER')) {
         $servers = WP_REDIS_CLUSTER;
     }
     if (defined('WP_REDIS_SERVERS')) {
         $servers = WP_REDIS_SERVERS;
     }
     if (!isset($servers)) {
         $servers = array($server);
     }
     return array_map(function ($parameters) {
         return is_string($parameters) ? Predis\Connection\Parameters::parse($parameters) : $parameters;
     }, $servers);
 }
<?php

/*
 * This file is part of the Predis\Async package.
 *
 * (c) Daniele Alessandri <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require __DIR__ . '/../autoload.php';
$loop = new React\EventLoop\StreamSelectLoop();
$parameters = Predis\Connection\Parameters::create('tcp://127.0.0.1:6379');
$profile = Predis\Profile\Factory::getDefault();
$connection = new Predis\Async\Connection\StreamConnection($loop, $parameters);
$connection->connect(function ($connection) use($profile) {
    $ping = $profile->createCommand('ping');
    $connection->executeCommand($ping, function ($response, $connection) use($profile) {
        $echo = $profile->createCommand('echo', [$response]);
        $connection->executeCommand($echo, function ($response, $connection) {
            var_dump($response);
            $connection->disconnect();
        });
    });
});
$loop->run();