Swoole-1.8.14版本增加一个兼容Redis服务器端协议的Server框架,可基于此框架实现Redis协议的服务器程序。Swoole\Redis\Server
继承自Swoole\Server
,可调用父类提供的所有方法。
Redis\Server
不需要设置onReceive
回调。实例程序:https://github.com/swoole/swoole-src/blob/master/examples/redis/server.php
redis-cli
、redis-benchmark
使用Redis客户端,需要安装hiredis库。下载hiredis
源码后,执行
make -j
sudo make install
sudo ldconfig
编译swoole是,在configure
指令中加入--enable-async-redis
./configure --enable-async-redis
make clean
make -j
sudo make install
$redis = new Swoole\Redis;
$redis->connect('127.0.0.1', 6379, function ($redis, $result) {
$redis->set('test_key', 'value', function ($redis, $result) {
$redis->get('test_key', function ($redis, $result) {
var_dump($result);
});
});
});
$cli = new Swoole\Http\Client('127.0.0.1', 80);
$cli->setHeaders(array('User-Agent' => 'swoole-http-client'));
$cli->setCookies(array('test' => 'value'));
$cli->post('/dump.php', array("test" => 'abc'), function ($cli) {
var_dump($cli->body);
$cli->get('/index.php', function ($cli) {
var_dump($cli->cookies);
var_dump($cli->headers);
});
});