Beispiel #1
0
<?php

$http = new swoole_http_server("127.0.0.1", 9501);
$http->set(['worker_num' => 8]);
require __DIR__ . '/src/Swoole/Async/RedisClient.php';
$redis = new Swoole\Async\RedisClient('127.0.0.1');
$http->on('request', function ($request, swoole_http_response $response) use($redis) {
    if (isset($request->get['status'])) {
        $response->end($redis->stats());
    } else {
        $redis->get('hello', function ($result, $success) use($response) {
            if (!$success) {
                echo "get from redis failed\n";
            }
            $response->end("<h1>Hello Swoole. value=" . $result . "</h1>");
        });
    }
});
$http->start();
Beispiel #2
0
<?php

require __DIR__ . '/../src/Swoole/Async/RedisClient.php';
$redis = new Swoole\Async\RedisClient('127.0.0.1');
$redis->hmset('hash2', array('key1' => 102, 'key2' => 'hello'), function ($result, $success) {
    echo $result;
});
Beispiel #3
0
<?php

require __DIR__ . '/src/Swoole/Async/RedisClient.php';
$redis = new Swoole\Async\RedisClient('127.0.0.1');
function redis_result($result, $success)
{
    echo "redis ok:\n";
    var_dump($success, $result);
}
$redis->select('2', function () use($redis) {
    $redis->set('key', 'value-rango', function ($result, $success) use($redis) {
        for ($i = 0; $i < 3; $i++) {
            $redis->get('key', 'redis_result');
        }
    });
});
Beispiel #4
0
<?php

require __DIR__ . '/../src/Swoole/Async/RedisClient.php';
$redis = new Swoole\Async\RedisClient('127.0.0.1');
$redis->hexists('hash2', 'key222', function ($result, $success) {
    var_dump($result);
});
Beispiel #5
0
<?php

require __DIR__ . '/../src/Swoole/Async/RedisClient.php';
$redis = new Swoole\Async\RedisClient('127.0.0.1');
$redis->sAdd('myset', "hello3", "world3", function ($result, $success) {
    var_dump($result);
});
Beispiel #6
0
<?php

require __DIR__ . '/../src/Swoole/Async/RedisClient.php';
$redis = new Swoole\Async\RedisClient('127.0.0.1');
$redis->get("big", function ($result, $success) {
    echo strlen($result);
});
Beispiel #7
0
<?php

require __DIR__ . '/../src/Swoole/Async/RedisClient.php';
$redis = new Swoole\Async\RedisClient('127.0.0.1');
$redis->debug = true;
$redis->sMembers('myset', function ($result, $success) {
    var_dump($result);
});
Beispiel #8
0
<?php

require __DIR__ . '/../src/Swoole/Async/RedisClient.php';
$redis = new Swoole\Async\RedisClient('127.0.0.1');
//$redis->debug = true;
$redis->hmget('hash2', array('key1', 'noexists', 'key2', 'key3'), function ($result, $success) {
    var_dump($result);
});