コード例 #1
0
ファイル: Redis.php プロジェクト: vzina/esaywork
 public function send(callable $callback)
 {
     $client = new \swoole_redis();
     $calltime = microtime(true);
     $key = md5($calltime . $this->_config['host'] . $this->_config['port'] . rand(0, 10000));
     $method = $this->_method;
     $params = $this->_argv;
     $db = (int) $this->_config['db'];
     array_push($params, function (\swoole_redis $redis, $result) use($callback, $key, $calltime) {
         call_user_func_array($callback, ['r' => 0, 'key' => $key, 'calltime' => $calltime, 'data' => $result]);
         $redis->close();
     });
     $client->connect($this->_config['host'], $this->_config['port'], function (\swoole_redis $client, $result) use($method, $params, $db) {
         $callback = end($params);
         if ($result == false) {
             call_user_func_array($callback, [$client, ['errCode' => $client->errCode, 'errMsg' => $client->errMsg]]);
             return;
         }
         if ($db) {
             $client->select($db, function (\swoole_redis $client, $result) use($method, $params, $callback) {
                 if ($result == false) {
                     call_user_func_array($callback, [$client, ['errCode' => $client->errCode, 'errMsg' => $client->errMsg]]);
                     return;
                 }
                 call_user_func_array([$client, $method], $params);
             });
             return;
         }
         call_user_func_array([$client, $method], $params);
     });
     unset($this->_method, $this->_argv);
 }
コード例 #2
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*__:*');
     });
 }
コード例 #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');
});
コード例 #4
0
ファイル: weather_server.php プロジェクト: noikiy/swoole-src
 function getResult4($response)
 {
     $client = new swoole_redis();
     $ip = "127.0.0.1";
     $port = 6379;
     $client->connect($ip, $port, function (swoole_redis $client, $result) use($response) {
         if ($result === false) {
             echo "connect to redis server failed\n";
             return false;
         }
         $client->GET('key', function (swoole_redis $client, $result) use($response) {
             //echo "get  result is :" . $result;
             $response->header('Content-Type', 'application/json');
             $response->end($result);
         });
     });
 }
コード例 #5
0
ファイル: client.php プロジェクト: noikiy/swoole-src
<?php

$client = new swoole_redis();
$client->connect('127.0.0.1', 6379, function (swoole_redis $client, $result) {
    echo "connect\n";
    $client->set('key', 'swoole', function (swoole_redis $client, $result) {
        echo "set key OK\n";
        $client->get('key', function (swoole_redis $client, $result) {
            var_dump($result);
            $client->keys('*', function (swoole_redis $client, $result) {
                var_dump($result);
                $client->close();
            });
        });
    });
});
コード例 #6
0
ファイル: client.php プロジェクト: l496501043/swoole-src
<?php

$client = new swoole_redis();
$client->connect('127.0.0.1', 6379, function (swoole_redis $client, $result) {
    $client->execute('SET key swoole', function (swoole_redis $client, $result) {
        var_dump($client, $result);
        $client->execute('get key', function (swoole_redis $client, $result) {
            var_dump($client, $result);
            $client->close();
        });
    });
});