123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace JinDouYun\Cache;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Factory;
- class SpecCache
- {
-
- private $onlineEnterpriseId;
-
- private $cache;
-
- private $specNameRelIdKey = 'SpecNameRelId';
-
- public function __construct($enterpriseId)
- {
- $this->onlineEnterpriseId = $enterpriseId;
- $this->cache = Factory::cache('mapping');
- }
-
- public function cacheSpecNameRelId($specName, $id)
- {
- return $this->cache->zadd($this->specNameRelIdKey.'::'.$this->onlineEnterpriseId, $id, $specName);
- }
-
- public function delSpecNameRelId($id)
- {
- return $this->cache->zremrangebyscore($this->specNameRelIdKey.'::'.$this->onlineEnterpriseId, $id,$id);
- }
-
- public function getSpecNameById($id)
- {
- $result = $this->cache->zrangebyscore($this->specNameRelIdKey.'::'.$this->onlineEnterpriseId, $id, $id);
- if (!$result) {
- return '';
- }
- return array_shift($result);
- }
-
- public function getIdBySpecName($specName)
- {
- $result = $this->cache->zscore($this->specNameRelIdKey.'::'.$this->onlineEnterpriseId, $specName);
- if (!$result) return 0;
- return $result;
- }
- }
|