redis edit
This commit is contained in:
parent
0afa013649
commit
6c74bde8e1
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue