CollectCache.Class.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * 收藏缓存
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/11/5
  7. * Time: 10:14
  8. */
  9. namespace JinDouYun\Cache;
  10. use Mall\Framework\Cache\Redis;
  11. use Mall\Framework\Factory;
  12. class CollectCache
  13. {
  14. /**
  15. * @var Redis
  16. */
  17. private $cache;
  18. protected $CollectKey = 'Collect';
  19. public function __construct()
  20. {
  21. $this->cache = Factory::cache('user');
  22. }
  23. /**
  24. * 缓存收藏
  25. * @param $enterpriseId
  26. * @param $userCenterId
  27. * @param $goodsId
  28. * @return
  29. */
  30. public function cacheCollect($enterpriseId, $userCenterId, $goodsId)
  31. {
  32. $this->cache->sadd($this->CollectKey.'::'.$enterpriseId.'::'.$userCenterId, $goodsId);
  33. }
  34. public function getCollect($enterpriseId, $userCenterId, $goodsId) {
  35. return $this->cache->sismember($this->CollectKey.'::'.$enterpriseId.'::'.$userCenterId, $goodsId);
  36. }
  37. public function delCollect($enterpriseId, $userCenterId, $goodsId) {
  38. return $this->cache->srem($this->CollectKey.'::'.$enterpriseId.'::'.$userCenterId, $goodsId);
  39. }
  40. public function getCollectList($enterpriseId,$userCenterId)
  41. {
  42. return $this->cache->smembers($this->CollectKey.'::'.$enterpriseId.'::'.$userCenterId);
  43. }
  44. }