redis->executeCommand('SISMEMBER', [$cacheKey, $userId]); if (empty($exists)) { Yii::$app->redis->executeCommand('SADD', [$cacheKey, $userId]); } // 只缓存1天:若未设置过期时间则设置为 86400 秒 $ttl = (int)Yii::$app->redis->executeCommand('TTL', [$cacheKey]); if ($ttl === -1) { Yii::$app->redis->executeCommand('EXPIRE', [$cacheKey, 86400]); } } //保存访客数 public static function saveVisit($shop, $visitNum, $date = null) { } /** * 获取访客数 * @param $shopId * @param null $date * @return int */ public static function getVisitNum($shopId, $date = null) { $date = isset($date) == false ? date("Ymd") : $date; $cacheKey = 'hd_visit:' . $shopId . '_' . $date; $num = Yii::$app->redis->executeCommand('SCARD', [$cacheKey]); return intval($num); } //获取访客ID public static function getVisitCustomIds($shopId, $date = null) { $date = isset($date) ? $date : date("Ymd"); $cacheKey = 'hd_visit:' . $shopId . '_' . $date; $userIds = Yii::$app->redis->executeCommand('SMEMBERS', [$cacheKey]); return $userIds; } }