コード例 #1
0
ファイル: DispatcherLoop.php プロジェクト: GunioRobot/predis
        $this->_events = array();
    }
    public function count()
    {
        return count($this->_events);
    }
    public function getEvents()
    {
        return $this->_events;
    }
    public function __invoke($payload)
    {
        $this->_events[] = $payload;
    }
}
// Attach our callable class to the dispatcher.
$dispatcher->attachCallback('events', $events = new EventsListener());
// Attach a function to control the dispatcher loop termination with a message.
$dispatcher->attachCallback('control', function ($payload) use($dispatcher) {
    if ($payload === 'terminate_dispatcher') {
        $dispatcher->stop();
    }
});
// Run the dispatcher loop until the callback attached to the 'control' channel
// receives 'terminate_dispatcher' as a message.
$dispatcher->run();
// Display our achievements!
echo "We received {$events->count()} messages!\n";
// Say goodbye :-)
$info = $client->info();
print_r("Goodbye from Redis v{$info['redis_version']}!\n");
コード例 #2
0
        $this->storeDebug($command, '->');
    }
    public function readResponse(CommandInterface $command)
    {
        $response = parent::readResponse($command);
        $this->storeDebug($command, '<-');
        return $response;
    }
    public function getDebugBuffer()
    {
        return $this->debugBuffer;
    }
}
$options = array('connections' => array('tcp' => 'SimpleDebuggableConnection'));
$client = new Predis\Client($single_server, $options);
$client->set('foo', 'bar');
$client->get('foo');
$client->info();
var_export($client->getConnection()->getDebugBuffer());
/* OUTPUT:
array (
  0 => 'SELECT 15 -> 127.0.0.1:6379 [0.0008s]',
  1 => 'SELECT 15 <- 127.0.0.1:6379 [0.001s]',
  2 => 'SET foo -> 127.0.0.1:6379 [0.001s]',
  3 => 'SET foo <- 127.0.0.1:6379 [0.0011s]',
  4 => 'GET foo -> 127.0.0.1:6379 [0.0013s]',
  5 => 'GET foo <- 127.0.0.1:6379 [0.0015s]',
  6 => 'INFO -> 127.0.0.1:6379 [0.0019s]',
  7 => 'INFO <- 127.0.0.1:6379 [0.0022s]',
)
*/
コード例 #3
0
ファイル: PubSubContext.php プロジェクト: dgw/ThinkUp
$pubsub->subscribe('notifications');
// Start processing the pubsup messages. Open a terminal and use redis-cli
// to push messages to the channels. Examples:
//   ./redis-cli PUBLISH notifications "this is a test"
//   ./redis-cli PUBLISH control_channel quit_loop
foreach ($pubsub as $message) {
    switch ($message->kind) {
        case 'subscribe':
            echo "Subscribed to {$message->channel}\n";
            break;
        case 'message':
            if ($message->channel == 'control_channel') {
                if ($message->payload == 'quit_loop') {
                    echo "Aborting pubsub loop...\n";
                    $pubsub->unsubscribe();
                } else {
                    echo "Received an unrecognized command: {$message->payload}.\n";
                }
            } else {
                echo "Received the following message from {$message->channel}:\n", "  {$message->payload}\n\n";
            }
            break;
    }
}
// Always unset the pubsub context instance when you are done! The
// class destructor will take care of cleanups and prevent protocol
// desynchronizations between the client and the server.
unset($pubsub);
// Say goodbye :-)
$info = $redis->info();
print_r("Goodbye from Redis v{$info['redis_version']}!\n");
コード例 #4
0
$pubsub->subscribe('control_channel', 'notifications');
// Start processing the pubsup messages. Open a terminal and use redis-cli
// to push messages to the channels. Examples:
//   ./redis-cli PUBLISH notifications "this is a test"
//   ./redis-cli PUBLISH control_channel quit_loop
foreach ($pubsub as $message) {
    switch ($message->kind) {
        case 'subscribe':
            echo "Subscribed to {$message->channel}", PHP_EOL;
            break;
        case 'message':
            if ($message->channel == 'control_channel') {
                if ($message->payload == 'quit_loop') {
                    echo "Aborting pubsub loop...", PHP_EOL;
                    $pubsub->unsubscribe();
                } else {
                    echo "Received an unrecognized command: {$message->payload}.", PHP_EOL;
                }
            } else {
                echo "Received the following message from {$message->channel}:", PHP_EOL, "  {$message->payload}", PHP_EOL, PHP_EOL;
            }
            break;
    }
}
// Always unset the pubsub consumer instance when you are done! The
// class destructor will take care of cleanups and prevent protocol
// desynchronizations between the client and the server.
unset($pubsub);
// Say goodbye :-)
$version = redis_version($client->info());
echo "Goodbye from Redis {$version}!", PHP_EOL;
コード例 #5
0
    public function readResponse(Predis\ICommand $command)
    {
        $reply = parent::readResponse($command);
        $this->storeDebug($command, '<-');
        return $reply;
    }
    public function getDebugBuffer()
    {
        return $this->_debugBuffer;
    }
}
$parameters = new Predis\ConnectionParameters($single_server);
$connection = new SimpleDebuggableConnection($parameters);
$redis = new Predis\Client($connection);
$redis->set('foo', 'bar');
$redis->get('foo');
$redis->info();
print_r($connection->getDebugBuffer());
/* OUTPUT:
Array
(
    [0] => SELECT 15 -> 127.0.0.1:6379 [0.0008s]
    [1] => SELECT 15 <- 127.0.0.1:6379 [0.0012s]
    [2] => SET foo -> 127.0.0.1:6379 [0.0014s]
    [3] => SET foo <- 127.0.0.1:6379 [0.0014s]
    [4] => GET foo -> 127.0.0.1:6379 [0.0016s]
    [5] => GET foo <- 127.0.0.1:6379 [0.0018s]
    [6] => INFO -> 127.0.0.1:6379 [0.002s]
    [7] => INFO <- 127.0.0.1:6379 [0.0025s]
)
*/
コード例 #6
0
ファイル: overview.php プロジェクト: ruurd/phpRedisAdmin
    if (!isset($server['db'])) {
        $server['db'] = 0;
    }
    // Setup a connection to this Redis server.
    $redis = new Predis\Client('tcp://' . $server['host'] . ':' . $server['port']);
    if (isset($server['auth'])) {
        if (!$redis->auth($server['auth'])) {
            die('ERROR: Authentication failed (' . $server['host'] . ':' . $server['port'] . ')');
        }
    }
    if ($server['db'] != 0) {
        if (!$redis->select($server['db'])) {
            die('ERROR: Selecting database failed (' . $server['host'] . ':' . $server['port'] . ',' . $server['db'] . ')');
        }
    }
    $info[$i] = $redis->info();
    $info[$i]['size'] = $redis->dbSize();
    if ($info[$i]['redis_version'] < '2.6') {
        $info[$i]['rdb_last_save_time'] = $info[$i]['last_save_time'];
    }
}
$page['css'][] = 'frame';
$page['js'][] = 'frame';
require 'header.inc.php';
?>

<?php 
foreach ($config['servers'] as $i => $server) {
    ?>
  <div class="server">
  <h2><?php