コード例 #1
0
ファイル: redis.php プロジェクト: ssdphp/ssdphp
 public function index()
 {
     $client = new \swoole_redis();
     $client->on('message', function (\swoole_redis $client, $result) {
         print_r($result);
     });
     $client->connect('127.0.0.1', 6379, function (\swoole_redis $client, $result) {
         echo "connect\n";
         $client->psubscribe('__key*__:*');
     });
 }
コード例 #2
0
ファイル: Redis.php プロジェクト: matyhtf/swoole_framework
 protected function connect()
 {
     $redis = new \swoole_redis();
     $redis->on('close', function ($redis) {
         $this->remove($redis);
     });
     return $redis->connect($this->config['host'], $this->config['port'], function ($redis, $result) {
         if ($result) {
             $this->join($redis);
         } else {
             $this->failure();
             trigger_error("connect to redis server[{$this->config['host']}:{$this->config['port']}] failed. Error: {$redis->errMsg}[{$redis->errCode}].");
         }
     });
 }
コード例 #3
0
ファイル: subscribe.php プロジェクト: noikiy/swoole-src
<?php

$client = new swoole_redis();
$client->on('message', function (swoole_redis $client, $result) {
    var_dump($result);
    static $more = false;
    if (!$more and $result[0] == 'message') {
        echo "subscribe new channel\n";
        $client->subscribe('msg_1', 'msg_2');
        $client->unsubscribe('msg_0');
        $more = true;
    }
});
$client->connect('127.0.0.1', 6379, function (swoole_redis $client, $result) {
    echo "connect\n";
    $client->subscribe('msg_0');
});