BookmarkService.php 657 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Services;
  3. use App\Bookmark;
  4. use Illuminate\Support\Facades\Cache;
  5. use Illuminate\Support\Facades\Redis;
  6. class BookmarkService
  7. {
  8. const CACHE_KEY = 'pf:services:bookmarks:';
  9. public static function get($profileId, $statusId)
  10. {
  11. if (!Redis::zcard(self::CACHE_KEY . $profileId)) {
  12. return false;
  13. }
  14. return Redis::zscore(self::CACHE_KEY . $profileId, $statusId) != null;
  15. }
  16. public static function add($profileId, $statusId)
  17. {
  18. return Redis::zadd(self::CACHE_KEY . $profileId, $statusId, $statusId);
  19. }
  20. public static function del($profileId, $statusId)
  21. {
  22. return Redis::zrem(self::CACHE_KEY . $profileId, $statusId);
  23. }
  24. }