Explorar o código

基于redis 实现在线状态检测

程旭源 hai 7 meses
pai
achega
e1a4dba15b
Modificáronse 2 ficheiros con 13 adicións e 2 borrados
  1. 11 1
      application/api/controller/Index.php
  2. 2 1
      composer.json

+ 11 - 1
application/api/controller/Index.php

@@ -83,12 +83,22 @@ class Index extends Api
     public function runrecord()
     {
         $nowtime = time();
-        $spacetime = 60 * 60;
+        $spacetime = 60 * 90;
+
+        $minTime = $nowtime - $spacetime;
+//        1711172121
+//        1711166775
+        $redis = new \Redis();
+        $redis->connect('127.0.0.1','6379');
+        $redis->zRemRangeByScore("live", 0, $minTime);
+        $uid = $redis->zRangeByScore("live", $minTime, $nowtime);
         $returndata = '';
         $userdata = db('admin')->field("id")
+            ->whereIn('id', $uid)
 //            ->where(['livetime' => ['gt', $nowtime - $spacetime]])
             ->where(['incomeendtime' => ['gt', $nowtime]])
             ->select();
+
         Db::startTrans();
         if (!$userdata) {
             $returndata = 'no data';

+ 2 - 1
composer.json

@@ -31,7 +31,8 @@
         "ext-pdo": "*",
         "ext-bcmath": "*",
         "txthinking/mailer": "^2.0",
-        "uduncloud/udun-wallet-sdk": "^1.0"
+        "uduncloud/udun-wallet-sdk": "^1.0",
+      "ext-redis": "*"
     },
     "config": {
         "preferred-install": "dist",