<?php * 每分鐘百萬(wàn)用戶,實(shí)時(shí)統(tǒng)計(jì)最近15分鐘在線用戶總數(shù) */ class OnlineUser { public $prefix_key = "online";//key前綴 public function __construct() { $this->redis = new Redis(); } /** * 往集合中添加新的在線用戶 * * @param $uid */ public function addUser($uid) { $this->redis->sAdd($this->prefix_key . date('hi'), $uid); } /** * 獲取在線用戶數(shù) * * @param $start_min 統(tǒng)計(jì)開(kāi)始分鐘 hi格式 * @param $end_min 統(tǒng)計(jì)結(jié)束的分鐘 * * @return mixed */ public function userNum($start_min, $end_min) { //第一個(gè)參數(shù),并集的key名稱 $params[] = $this->prefix_key . $start_min . '_' . $end_min; //遍歷時(shí)間區(qū)間內(nèi)所有的分鐘,并放入到參數(shù)中 for ($min = $start_min; $min < $end_min; $min++) { $params[] = $this->prefix_key . $min; } //求所有分鐘的用戶的并集并保存,性能比直接計(jì)算返回快很多,省去了數(shù)據(jù)傳輸 $num = call_user_func_array([$this->redis, "sUnionStore"], $params); //刪除臨時(shí)并集 $this->redis->delete($params[0]); return $num; } }
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Oguri Cap Build Guide | A Pretty Derby Musume
1 weeks ago
By Jack chen
Guide: Stellar Blade Save File Location/Save File Lost/Not Saving
3 weeks ago
By DDD
Dune: Awakening - Advanced Planetologist Quest Walkthrough
3 weeks ago
By Jack chen
Agnes Tachyon Build Guide | A Pretty Derby Musume
1 weeks ago
By Jack chen
Date Everything: Dirk And Harper Relationship Guide
3 weeks ago
By Jack chen

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
