123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace JinDouYun\Cache;
- use Mall\Framework\Cache\Redis;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Factory;
- class GoodsBasicCache
- {
-
- private $cache;
- private $onlineEnterpriseId;
- protected $categoryKey = 'categoryAndBasicNum';
- protected $brandKey = 'brandAndBasicNum';
-
- public function __construct($enterpriseId)
- {
- $this->onlineEnterpriseId = $enterpriseId;
- $this->cache = Factory::cache('default');
- }
-
- public function cacheCategoryRelationGoodsBasicNum($categoryId, $num)
- {
- $result = $this->cache->zadd($this->categoryKey.'::'.$this->onlineEnterpriseId, $num, $categoryId);
- return $result;
- }
-
- public function categoryKeyScoreIncr($categoryId)
- {
- $result = $this->cache->zincrby($this->categoryKey.'::'.$this->onlineEnterpriseId, 1, $categoryId);
- return $result;
- }
-
- public function categoryKeyScoreDecr($categoryId)
- {
- $result = $this->cache->zincrby($this->categoryKey.'::'.$this->onlineEnterpriseId, -1, $categoryId);
- return $result;
- }
-
- public function getCategoryGoodsBasicNum($categoryId)
- {
- $result = $this->cache->zscore($this->categoryKey.'::'.$this->onlineEnterpriseId, $categoryId);
- return $result;
- }
-
-
- public function cacheBrandRelationGoodsBasicNum($brandId,$num)
- {
- $result = $this->cache->zadd($this->brandKey.'::'.$this->onlineEnterpriseId, $num, $brandId);
- if ($result == false){
- return 0;
- }
- return $result;
- }
-
- public function brandKeyScoreIncr($brandId)
- {
- $result = $this->cache->zincrby($this->brandKey.'::'.$this->onlineEnterpriseId, 1, $brandId);
- return $result;
- }
-
- public function brandKeyScoreDecr($brandId)
- {
- $result = $this->cache->zincrby($this->brandKey.'::'.$this->onlineEnterpriseId, -1, $brandId);
- return $result;
- }
-
- public function getBrandGoodsBasicNum($brandId)
- {
- $result = $this->cache->zscore($this->brandKey.'::'.$this->onlineEnterpriseId, $brandId);
- return $result;
- }
- }
|