123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace JinDouYun\Cache;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Factory;
- class CacheMan
- {
- private $cache;
- private $enterpriseId;
- private $userCenterId;
- private static $cacheKey = '';
- public function __construct($enterpriseId, $userCenterId = false)
- {
- $this->enterpriseId = $enterpriseId;
- $this->userCenterId = $userCenterId;
- $this->cache = Factory::cache('mapping');
- }
-
-
- public function addCacheHash($key,$value, $cacheKey)
- {
- $data = json_encode($value);
- $result = $this->cache->hset($cacheKey . '::' . $this->enterpriseId, $key, $data);
- if (!$result) {
- return ResultWrapper::fail('error', ErrorCode::$redisWriteError);
- }
- return ResultWrapper::success('success');
- }
-
- public function getCacheHash($key, $cacheKey, $type = false)
- {
- $result = $this->cache->hget($cacheKey.'::'.$this->enterpriseId, $key);
- if (!$result) return '';
- $returnData = json_decode($result, true);
- if($type){
- return $returnData[$type];
- }
- return $returnData;
- }
-
- public function delCacheHash($key, $cacheKey)
- {
- $this->cache->hdel($cacheKey.'::'.$this->enterpriseId, $key);
- }
-
-
- public function createCacheStatistics($value,$score,$cacheKey)
- {
- $result = $this->cache->zadd($cacheKey.'::'.$this->enterpriseId, $score, $value);
- if ($result == false){
- return false;
- }
- return $result;
- }
-
- public function getCacheSortedSet($value,$cacheKey)
- {
- $result = $this->cache->ZSCORE($cacheKey.'::'.$this->enterpriseId,$value);
- return $result;
- }
-
- public function getCacheKeySortedSetCount($cacheKey)
- {
- $result = $this->cache->ZCARD($cacheKey.'::'.$this->enterpriseId);
- return $result;
- }
-
- public function deleteCacheKey($cacheKey)
- {
- $result = $this->cache->del($cacheKey.'::'.$this->enterpriseId);
- return $result;
- }
- }
|