1 Star 0 Fork 14

wangwynn/swoole-redis

forked from sethink/swoole-redis
关闭
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Demo.php 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
sethink 提交于 2019-01-09 18:14 . modify
<?php
namespace Demo;
include_once "./src/CoRedis.php";
include_once "./src/RedisPool.php";
include_once "./src/map/CoRedisMap.php";
use swoole;
use sethink\swooleRedis\CoRedis;
use sethink\swooleRedis\RedisPool;
class Demo
{
protected $server;
protected $RedisPool;
public function __construct()
{
$this->server = new Swoole\Http\Server("0.0.0.0", 9501);
$this->server->set(array(
'worker_num' => 4,
'max_request' => 50000,
'reload_async' => true,
'max_wait_time' => 30,
));
$this->server->on('Start', function ($server) {
});
$this->server->on('ManagerStart', function ($server) {
});
$this->server->on('WorkerStart', array($this, 'onWorkerStart'));
$this->server->on('WorkerStop', function ($server, $worker_id) {
});
$this->server->on('open', function ($server, $request) {
});
$this->server->on('Request', array($this, 'onRequest'));
$this->server->start();
}
public function onWorkerStart($server, $worker_id)
{
$config = [
'host' => '127.0.0.1',
'port' => 6379,
'auth' => 'sethink',
'poolMin' => 5,
'clearTime' => 60000,
'clearAll' => 300000,
'setDefer' => true,
'timeout' => 5
];
$this->RedisPool = new RedisPool($config);
unset($config);
$this->RedisPool->clearTimer($this->server);
}
public function onRequest($request, $response)
{
// $rs1 = CoRedis::init($this->RedisPool)
// ->setDefer(false)
// ->set('sethink', 'sethink');
// var_dump($rs1);
$rs2 = CoRedis::init($this->RedisPool)->get('sethink');
// var_dump($rs2);
// $redis = CoRedis::init($this->RedisPool)->instance();
// CoRedis::init($this->RedisPool)->put($redis);
// go(function (){
// $redis = CoRedis::init($this->RedisPool)->instance();
// $rs = $redis->get('string');
// var_dump($rs);
// CoRedis::init($this->RedisPool)->put($redis);
// });
echo PHP_EOL;
}
}
new Demo();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/wangwynn/swoole-redis.git
git@gitee.com:wangwynn/swoole-redis.git
wangwynn
swoole-redis
swoole-redis
master

搜索帮助