You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
15
vendor/swoole/tests/include/api/swoole_redis/connect_timeout.php
vendored
Executable file
15
vendor/swoole/tests/include/api/swoole_redis/connect_timeout.php
vendored
Executable file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
$redis = new swoole_redis();
|
||||
$redis->on("close", function (){
|
||||
echo "closed\n";
|
||||
});
|
||||
|
||||
$redis->on("message", function (){
|
||||
echo "message\n";
|
||||
});
|
||||
|
||||
$result = $redis->connect("192.1.1.1", 9000, function ($redis, $result)
|
||||
{
|
||||
assert($redis->errCode == SOCKET_ETIMEDOUT);
|
||||
assert($result === false);
|
||||
});
|
61
vendor/swoole/tests/include/api/swoole_redis/doublefree_client.php
vendored
Executable file
61
vendor/swoole/tests/include/api/swoole_redis/doublefree_client.php
vendored
Executable file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
function get(\swoole_redis $redis)
|
||||
{
|
||||
// TODO 为什么需要timer,否则call返回false TIMER ???
|
||||
swoole_timer_after(1, function() use($redis) {
|
||||
$r = $redis->get("HELLO", function(\swoole_redis $redis, $result) {
|
||||
var_dump($result);
|
||||
get($redis);
|
||||
});
|
||||
assert($r);
|
||||
$redis->close();
|
||||
test();
|
||||
});
|
||||
}
|
||||
|
||||
function test()
|
||||
{
|
||||
$redis = new \swoole_redis();
|
||||
$redis->on("close", function(\swoole_redis $redis) {
|
||||
echo "close\n\n";
|
||||
test();
|
||||
// 死循环
|
||||
// $swoole_redis->close();
|
||||
});
|
||||
|
||||
$redis->connect("127.0.0.1", 6379, function(\swoole_redis $redis, $connected) {
|
||||
assert($connected);
|
||||
// get($swoole_redis);
|
||||
$redis->get("HELLO", function(\swoole_redis $redis, $result) {});
|
||||
});
|
||||
}
|
||||
|
||||
test();
|
||||
return;
|
||||
|
||||
function test1() {
|
||||
$redis = new \swoole_redis();
|
||||
$redis->on("close", function() { echo "close"; });
|
||||
|
||||
$redis->connect("127.0.0.1", 6379, function(\swoole_redis $redis, $connected) {
|
||||
assert($connected);
|
||||
|
||||
swoole_timer_after(1, function() use($redis) {
|
||||
$r = $redis->get("HELLO", function(\swoole_redis $redis, $result) {
|
||||
var_dump($redis);
|
||||
var_dump($result);
|
||||
test();
|
||||
});
|
||||
assert($r);
|
||||
swoole_timer_after(1, function() use($redis) {
|
||||
// $r = $swoole_redis->close();
|
||||
// var_dump($r);
|
||||
// $swoole_redis->close();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
test1();
|
||||
|
54
vendor/swoole/tests/include/api/swoole_redis/doublefree_server.php
vendored
Executable file
54
vendor/swoole/tests/include/api/swoole_redis/doublefree_server.php
vendored
Executable file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
(new FakeRedisServer())->start();
|
||||
|
||||
class FakeRedisServer
|
||||
{
|
||||
public $swooleServer;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->swooleServer = new \swoole_server("0.0.0.0", 6379, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
|
||||
$this->swooleServer->set(["worker_num" => 1]);
|
||||
}
|
||||
|
||||
public function start()
|
||||
{
|
||||
$this->swooleServer->on('start', [$this, 'onStart']);
|
||||
$this->swooleServer->on('shutdown', [$this, 'onShutdown']);
|
||||
|
||||
$this->swooleServer->on('workerStart', [$this, 'onWorkerStart']);
|
||||
$this->swooleServer->on('workerStop', [$this, 'onWorkerStop']);
|
||||
$this->swooleServer->on('workerError', [$this, 'onWorkerError']);
|
||||
|
||||
$this->swooleServer->on('connect', [$this, 'onConnect']);
|
||||
$this->swooleServer->on('receive', [$this, 'onReceive']);
|
||||
|
||||
$this->swooleServer->on('close', [$this, 'onClose']);
|
||||
|
||||
$this->swooleServer->start();
|
||||
}
|
||||
|
||||
public function onClose() {}
|
||||
public function onStart(swoole_server $swooleServer) {}
|
||||
public function onShutdown(swoole_server $swooleServer) {}
|
||||
public function onWorkerStart(swoole_server $swooleServer, $workerId) {}
|
||||
public function onWorkerStop(swoole_server $swooleServer, $workerId) {}
|
||||
public function onWorkerError(swoole_server $swooleServer, $workerId, $workerPid, $exitCode, $sigNo) {}
|
||||
|
||||
public function onConnect(swoole_server $swooleServer, $fd) {
|
||||
// $swooleServer->close($fd);
|
||||
}
|
||||
|
||||
public function onReceive(swoole_server $swooleServer, $fd, $fromId, $data)
|
||||
{
|
||||
$swooleServer->send($fd, "\0");
|
||||
return;
|
||||
|
||||
$swooleServer->send($fd, "$-1\r\n");
|
||||
echo $data;
|
||||
swoole_timer_after(1000, function() use($swooleServer, $fd) {
|
||||
$swooleServer->close($fd);
|
||||
});
|
||||
}
|
||||
}
|
13
vendor/swoole/tests/include/api/swoole_redis/redis_server_without_response.php
vendored
Executable file
13
vendor/swoole/tests/include/api/swoole_redis/redis_server_without_response.php
vendored
Executable file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
$host = isset($argv[1]) ? $argv[1] : HTTP_SERVER_HOST;
|
||||
$port = isset($argv[2]) ? $argv[2] : HTTP_SERVER_PORT;
|
||||
|
||||
$swoole = new swoole_server($host, $port);
|
||||
|
||||
$swoole->on("connect", function ($server, $fd) {
|
||||
});
|
||||
|
||||
$swoole->on("receive", function ($server, $fd, $from_id, $data) {
|
||||
});
|
||||
|
||||
$swoole->start();
|
67
vendor/swoole/tests/include/api/swoole_redis/redis_test.php
vendored
Executable file
67
vendor/swoole/tests/include/api/swoole_redis/redis_test.php
vendored
Executable file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
define("REDIS_SERVER_HOST", "127.0.0.1");
|
||||
define("REDIS_SERVER_PORT", 6379);
|
||||
|
||||
$redis = new \swoole_redis();
|
||||
$redis->on("close", function() { echo "close"; });
|
||||
|
||||
// !!!! For SUBSCRIBE
|
||||
$redis->on("message", function() { var_dump(func_get_args()); });
|
||||
|
||||
$redis->connect(REDIS_SERVER_HOST, REDIS_SERVER_PORT, function(\swoole_redis $redis, $connected) {
|
||||
if ($connected === false) {
|
||||
fputs(STDERR, "ERROR:$redis->errMsg($redis->errCode)\n");
|
||||
echo "connected fail";
|
||||
return;
|
||||
}
|
||||
echo "connected\n";
|
||||
|
||||
$luaScript = <<<LUA
|
||||
error scripr
|
||||
LUA;
|
||||
$redis->eval($luaScript, 0, function(\swoole_redis $redis, $result) {
|
||||
if ($result === false) {
|
||||
// TODO WTF ? 错误信息呢?!
|
||||
// 这里的errMsg 与 errCode是socket的
|
||||
// 那redis原生的呢?!
|
||||
// 抓包可以看到错误返回信息
|
||||
fputs(STDERR, "ERROR:$redis->errMsg($redis->errCode)\n");
|
||||
} else {
|
||||
var_dump($result);
|
||||
}
|
||||
$redis->close();
|
||||
});
|
||||
return;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* evalsha
|
||||
* SCRIPT FLUSH :清除所有脚本缓存
|
||||
* SCRIPT EXISTS :根据给定的脚本校验和,检查指定的脚本是否存在于脚本缓存
|
||||
* SCRIPT LOAD :将一个脚本装入脚本缓存,但并不立即运行它
|
||||
* SCRIPT KILL :杀死当前正在运行的脚本
|
||||
*/
|
||||
|
||||
$luaScript = <<<LUA
|
||||
return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}
|
||||
LUA;
|
||||
$keyNum = 2;
|
||||
$key1 = "key1";
|
||||
$key2 = "key2";
|
||||
$val1 = "first";
|
||||
$val2 = "second";
|
||||
$r = $redis->eval($luaScript, $keyNum, $key1, $key2, $val1, $val2, function(\swoole_redis $redis, $result) {
|
||||
if ($result === false) {
|
||||
var_dump($redis);
|
||||
redis_error($redis);
|
||||
// WTF
|
||||
// -ERR Error compiling script (new swoole_function): user_script:1: unfinished string near '<eof>'
|
||||
} else {
|
||||
var_dump($result);
|
||||
}
|
||||
$redis->close();
|
||||
});
|
||||
assert($r === true);
|
||||
});
|
43
vendor/swoole/tests/include/api/swoole_redis/simple_redis.php
vendored
Executable file
43
vendor/swoole/tests/include/api/swoole_redis/simple_redis.php
vendored
Executable file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/../../../include/bootstrap.php";
|
||||
|
||||
|
||||
class Obj
|
||||
{
|
||||
}
|
||||
|
||||
$redis = new swoole_redis();
|
||||
$redis->on("close", function ()
|
||||
{
|
||||
echo "close";
|
||||
});
|
||||
$redis->on("message", function ()
|
||||
{
|
||||
var_dump(func_get_args());
|
||||
});
|
||||
|
||||
define('REDIS_TEST_KEY', "swoole:test:key_" . md5(microtime()));
|
||||
define('REDIS_TEST_VALUE', RandStr::gen(128, RandStr::ALPHA | RandStr::NUM | RandStr::CHINESE));
|
||||
|
||||
// $swoole_redis->connect(REDIS_SERVER_PATH, false, swoole_function() {}); TODO
|
||||
$redis->connect(REDIS_SERVER_HOST, REDIS_SERVER_PORT, function (\swoole_redis $redis)
|
||||
{
|
||||
$redis->get(REDIS_TEST_KEY, function (\swoole_redis $redis, $result)
|
||||
{
|
||||
assert($result === null);
|
||||
$redis->set(REDIS_TEST_KEY, REDIS_TEST_VALUE, function (\swoole_redis $redis, $result)
|
||||
{
|
||||
assert($result === 'OK');
|
||||
$redis->get(REDIS_TEST_KEY, function (\swoole_redis $redis, $result)
|
||||
{
|
||||
assert($result === REDIS_TEST_VALUE);
|
||||
$redis->del(REDIS_TEST_KEY, function (\swoole_redis $redis, $result)
|
||||
{
|
||||
assert($result === 1);
|
||||
$redis->close();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user