From 6c74bde8e17b8e680d048629806f96622c5e1178 Mon Sep 17 00:00:00 2001 From: ASUS <515617283@qq.com> Date: Mon, 13 Oct 2025 15:11:11 +0800 Subject: [PATCH] redis edit --- extend/workermans/model/Base.php | 88 ++++++++++++++++---------------- 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/extend/workermans/model/Base.php b/extend/workermans/model/Base.php index fecece4..ee09690 100644 --- a/extend/workermans/model/Base.php +++ b/extend/workermans/model/Base.php @@ -713,61 +713,59 @@ class Base extends Model */ public static function add_total_number(string $client_id, string $type = null, $total = null) { - $redis = self::$redis; $redis_name = date('Y-m-d') . '_online_number'; - $redis->get($redis_name, function ($result, $redis) use ($redis_name, $client_id, $type, $total) { - if($result) { - $result_arr = json_decode($result, true); - if($type) { - if(isset($result_arr[$type])) { - if (!in_array($client_id, $result_arr[$type])) { - // 新增 - array_push($result_arr[$type], $client_id); - } - }else { - $result_arr[$type] = [$client_id]; + $result = Redis::get($redis_name); + if($result) { + $result_arr = json_decode($result, true); + if($type) { + if(isset($result_arr[$type])) { + if (!in_array($client_id, $result_arr[$type])) { + // 新增 + array_push($result_arr[$type], $client_id); } }else { - foreach ($result_arr as $type_str => $client_arr) { - $key = array_search($client_id, $client_arr); - if($key !== false) { - // 关闭 - unset($result_arr[$type_str][$key]); - $result_arr[$type_str] = array_values($result_arr[$type_str]); - } - } - if(!empty($result_arr['total'])) { - $key = array_search($client_id, $result_arr['total']); - if($key !== false) { - unset($result_arr['total'][$key]); - $result_arr['total'] = array_values($result_arr['total']); - } - } - } - if($total) { - if(isset($result_arr['total'])) { - if (!in_array($client_id, $result_arr['total'])) { - // 新增 - array_push($result_arr['total'], $client_id); - } - }else { - $result_arr['total'] = [$client_id]; - } - } - }else { - if($type) { $result_arr[$type] = [$client_id]; } - if($total) { + }else { + foreach ($result_arr as $type_str => $client_arr) { + $key = array_search($client_id, $client_arr); + if($key !== false) { + // 关闭 + unset($result_arr[$type_str][$key]); + $result_arr[$type_str] = array_values($result_arr[$type_str]); + } + } + if(!empty($result_arr['total'])) { + $key = array_search($client_id, $result_arr['total']); + if($key !== false) { + unset($result_arr['total'][$key]); + $result_arr['total'] = array_values($result_arr['total']); + } + } + } + if($total) { + if(isset($result_arr['total'])) { + if (!in_array($client_id, $result_arr['total'])) { + // 新增 + array_push($result_arr['total'], $client_id); + } + }else { $result_arr['total'] = [$client_id]; } } - if(isset($result_arr)) { - $redis->set($redis_name, json_encode($result_arr), 60 * 60 * 24); + }else { + if($type) { + $result_arr[$type] = [$client_id]; } - }); + if($total) { + $result_arr['total'] = [$client_id]; + } + } + if(isset($result_arr)) { + Redis::set($redis_name, json_encode($result_arr), 60 * 60 * 24); + } if(!$type) { - $redis->del($client_id); + Redis::del($client_id); } }