redis edit
This commit is contained in:
@@ -25,13 +25,10 @@ class Events
|
||||
{
|
||||
// $url = 'http://127.0.0.1:8686/?method=sendToUid&account=101¶ms={"data_type":"order","order_id":"2541"}';
|
||||
// $url = 'https://sockets.sxczgkj.com/s/account/overview';
|
||||
// 启动redis
|
||||
RedisInit::inits();
|
||||
// 开启内部通讯接口。便于内部通讯
|
||||
$http_worker = new Worker('http://127.0.0.1:8686');
|
||||
$http_worker->reusePort = true;
|
||||
$redis = Base::$redis;
|
||||
$http_worker->onMessage = function (TcpConnection $connection, Request $request) use($redis) {
|
||||
$http_worker->onMessage = function (TcpConnection $connection, Request $request) {
|
||||
$method = $request->get('method');
|
||||
$account = $request->get('account');
|
||||
$params = $request->get('params');
|
||||
@@ -40,19 +37,18 @@ class Events
|
||||
$params_arr = json_decode($params, true);
|
||||
// 如果是订单打印并且通过uid推送, 保存redis
|
||||
if($params_arr['operate_type'] == 'order_print' && $method == 'sendToUid') {
|
||||
$redis->get($params_arr['send_id'], function ($result)use($params_arr, $params){
|
||||
if($result) {
|
||||
$msg_id_arr = json_decode($result, true);
|
||||
$msg_id_arr_c = count($msg_id_arr);
|
||||
$msg_id_arr[$msg_id_arr_c] = $params_arr;
|
||||
$result_n = json_encode($msg_id_arr);
|
||||
Base::setredis_new($result_n, $params_arr['send_id']);
|
||||
}else {
|
||||
$params_arr_n[] = $params_arr;
|
||||
print_r('数组-------->' . json_encode($params_arr_n)) . "\r\n";
|
||||
Base::setredis_new(json_encode($params_arr_n), $params_arr['send_id']);
|
||||
}
|
||||
});
|
||||
$result = Redis::get($params_arr['send_id']);
|
||||
if($result) {
|
||||
$msg_id_arr = json_decode($result, true);
|
||||
$msg_id_arr_c = count($msg_id_arr);
|
||||
$msg_id_arr[$msg_id_arr_c] = $params_arr;
|
||||
$result_n = json_encode($msg_id_arr);
|
||||
Base::setredis_new($result_n, $params_arr['send_id']);
|
||||
}else {
|
||||
$params_arr_n[] = $params_arr;
|
||||
print_r('数组-------->' . json_encode($params_arr_n)) . "\r\n";
|
||||
Base::setredis_new(json_encode($params_arr_n), $params_arr['send_id']);
|
||||
}
|
||||
}
|
||||
|
||||
return $connection->send('ok');
|
||||
@@ -64,8 +60,6 @@ class Events
|
||||
print_r('定时器');
|
||||
// 启动定时器 定时器处理消息回执/在线列表
|
||||
$_SESSION['auth_timer_id'] = Timer::add(10, function (){
|
||||
// print_r('时间--->' . date('Y-m-d H:i:s') . "\r\n");
|
||||
// print_r( "\r\n");
|
||||
Base::geteventredis_new();
|
||||
});
|
||||
}
|
||||
@@ -172,13 +166,11 @@ class Events
|
||||
$gate_way = GateWay::class;
|
||||
$number = $message['number'];
|
||||
try {
|
||||
$redis = self::$redis;
|
||||
$redis->select(3);
|
||||
$red_number = $redis->get('shop:' . $message['shop_id'] . ':product-stock:' . $message['product_id']);
|
||||
Redis::select(3);
|
||||
$red_number = Redis::get('shop:' . $message['shop_id'] . ':product-stock:' . $message['product_id']);
|
||||
}catch (\Exception $e) {
|
||||
print_r( "Redis 错误: " . $e->getMessage() . "\r\n");
|
||||
}
|
||||
$redis->close();
|
||||
print_r('库存数量-->' . $red_number . "\r\n" . date('Y-m-d H:i:s'));
|
||||
if(is_numeric($red_number)) {
|
||||
// 起售数量和库存之间的处理
|
||||
|
||||
Reference in New Issue
Block a user