AccountStatService.php 946 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Services\Account;
  3. use Illuminate\Support\Facades\Redis;
  4. class AccountStatService
  5. {
  6. const REFRESH_CACHE_KEY = 'pf:services:accountstats:refresh:daily';
  7. public static function incrementPostCount($pid)
  8. {
  9. return Redis::zadd(self::REFRESH_CACHE_KEY, $pid, $pid);
  10. }
  11. public static function decrementPostCount($pid)
  12. {
  13. return Redis::zadd(self::REFRESH_CACHE_KEY, $pid, $pid);
  14. }
  15. public static function removeFromPostCount($pid)
  16. {
  17. return Redis::zrem(self::REFRESH_CACHE_KEY, $pid);
  18. }
  19. public static function getAllPostCountIncr($limit = -1)
  20. {
  21. return Redis::zrange(self::REFRESH_CACHE_KEY, 0, $limit);
  22. }
  23. public static function getPostCountChunk($lastId, $count)
  24. {
  25. return Redis::zrangebyscore(
  26. self::REFRESH_CACHE_KEY,
  27. '('.$lastId,
  28. '+inf',
  29. ['limit' => [0, $count]]
  30. );
  31. }
  32. }