🚀 更新框架中Cache使用的参数

🚀 更新README.md
This commit is contained in:
jerry 2018-12-02 19:59:43 +08:00
parent a7ba5a3c3d
commit f808a1b3a3
4 changed files with 24 additions and 18 deletions

View File

@ -19,9 +19,12 @@ Swoole的用处最简单可以理解为只需要简单几行代码即可运
[Swoole官网](https://www.swoole.com/)
## CQBot-swoole 文档
本项目的文档正在努力编写中:[https://cqbot.crazywhale.org/](https://cqbot.crazywhale.org/)
## 框架简介
本机器人框架是基于PHP Swoole框架而写的一个CQHTTPAPI SDK具有高性能、高并发和多机器人连接的特性。框架本身常驻内存的特性解决了读写文件、读写数据库等造成的性能问题。
本机器人框架是基于PHP Swoole框架而写的一个CQ-HTTP-API SDK具有高性能、高并发和多机器人连接的特性。框架本身常驻内存的特性解决了读写文件、读写数据库等造成的性能问题。
框架自身作为一个高性能的Swoole **WebSocket**兼容HTTP服务器可以同时完成更多websocket和HTTP环境的业务逻辑。此外还保留了微信公众号接口未来可以与微信公众号开发者平台对接。
@ -29,7 +32,7 @@ Swoole的用处最简单可以理解为只需要简单几行代码即可运
## 环境部署
由于框架是独立于酷Q和HTTPAPI插件运行的故你可以在多台主机上部署酷Q的docker。
如果你是新用户或重新安装含有HTTPAPI插件的**酷Q-Docker**的话可以在你需要部署酷Q的Linux主机下使用下面的脚本快速构建酷Q环境。
如果你是新用户或重新安装含有HTTPAPI插件的**酷Q-Docker**的话可以在你需要部署酷Q的Linux主机下使用下面的脚本快速构建酷Q环境此脚本会引导进行相关的cqhttp插件设置每台部署酷Q的主机均可直接使用此条命令服务器需要提前安装Docker
```shell
curl -O https://raw.githubusercontent.com/crazywhalecc/CQBot-swoole/master/start-coolq.sh
@ -68,7 +71,7 @@ chmod +x start-docker.sh
```
## 启动框架
## 启动
#### 直接安装后启动框架(第一次会有初始化设置)
```shell
@ -88,6 +91,9 @@ chmod +x start-screen.sh
```shell
sudo docker run -it --rm --name cqbot -v $(pwd)/cqbot/:/root/ jesse2061/cqbot-swoole
# 进入docker后输入
php start.php
```
#### 使用Docker在screen中运行框架

View File

@ -87,7 +87,7 @@ class RobotWSConnection extends WSConnection
StatusParser::parse($response, $data);
if ($s["func"] !== null)
call_user_func($s["func"], $response, $data);
Cache::unset("sent_api", $data["echo"]);
Cache::removeKey("sent_api", $data["echo"]);
return false;
}
}
@ -120,7 +120,7 @@ class RobotWSConnection extends WSConnection
StatusParser::parse($response, $data);
if ($s["func"] !== null)
call_user_func($s["func"], $response, $data);
Cache::unset("sent_api", $data["echo"]);
Cache::removeKey("sent_api", $data["echo"]);
return false;
}
}

View File

@ -55,7 +55,7 @@ class WSMessageEvent extends ServerEvent
StatusParser::parse($response, $origin);
if ($origin["func"] !== null)
call_user_func($origin["func"], $response, $origin);
Cache::unset("sent_api", $req["echo"]);
Cache::removeKey("sent_api", $req["echo"]);
}
}
break;

View File

@ -15,8 +15,6 @@ class Cache
static $data = [];
/** @var \swoole_websocket_server $server */
static $server;
/** @var swoole_http_client $http_client */
static $http_client;
/** @var Scheduler $scheduler */
static $scheduler;
@ -33,27 +31,29 @@ class Cache
/** @var WSConnection[] $connect */
static $connect = [];
static function get($name){ return self::$data[$name] ?? null; }
static function get($name) { return self::$data[$name] ?? null; }
static function set($name, $value){ self::$data[$name] = $value; }
static function set($name, $value) { self::$data[$name] = $value; }
static function append($name, $value){ self::$data[$name][] = $value; }
static function append($name, $value) { self::$data[$name][] = $value; }
static function appendKey($name, $key, $value){ self::$data[$name][$key] = $value; }
static function appendKey($name, $key, $value) { self::$data[$name][$key] = $value; }
static function unset($name, $key){ unset(self::$data[$name][$key]); }
static function removeKey($name, $key) { unset(self::$data[$name][$key]); }
static function unsetByValue($name, $vale){
static function removeValue($name, $vale) {
$key = array_search($vale, self::$data[$name]);
array_splice(self::$data[$name], $key, 1);
}
static function isset($name){ return isset(self::$data[$name]); }
static function unset($name) { unset(self::$data[$name]); }
static function array_key_exists($name, $key){ return isset(self::$data[$name][$key]); }
static function isset($name) { return isset(self::$data[$name]); }
static function in_array($name, $value){
if(!is_array((self::$data[$name] ?? 1))) return false;
static function array_key_exists($name, $key) { return isset(self::$data[$name][$key]); }
static function in_array($name, $value) {
if (!is_array((self::$data[$name] ?? 1))) return false;
return in_array($value, self::$data[$name]);
}
}