swoole 连接多台 redis示例

$http = new swoole_http_server("127.0.0.1", 9501);
$http->set(['worker_num' => 8]);
require __DIR__.'/src/Swoole/Async/RedisClient.php';

$redis_pool[] = new Swoole\Async\RedisClient('127.0.0.1',6379);
$redis_pool[] = new Swoole\Async\RedisClient('127.0.0.1',6380);

$http->on('request', function ($request, swoole_http_response $response) use ($redis_pool) {

    $redis = $redis_pool[array_rand($redis_pool)];

    $arr= array("key1"=>10000);
       $redis->hmset("aaad",$arr,function ($result, $success) use ($redis){

    });

    if (isset($request->get['status'])) {
        $response->end($redis->stats());
    } else {
        $redis->hmget(
            "aaad",
            array("key1"),
            function ($result, $success) use ($response) {
                if (!$success) {
                    echo "get from redis failed\n";
                }
                $response->end("<h1>session =" . json_encode($result) . "</h1>");
            }
        );
    }
});

$http->start();


你可能感兴趣的:(swoole 连接多台 redis示例)