redis cache 操作封装

@param Context $context 请求上下文对象
@param string $key Redis Key
@param string $value Redis Value
@param int $expire 过期时间，单位秒
@return mixed|Redis
186398
public function cache($context, string $key, $value = '', int $expire = 0)
    {
        if ($value === '') {
            $commandData = [$context, $key];
            $command = 'get';
        } else {
            if (!empty($expire)) {
                $command = 'setex';
                $commandData = [$context, $key, $expire, $value];
            } else {
                $command = 'set';
                $commandData = [$context, $key, $value];
            }
        }

        return $this->__call($command, $commandData);
    }
150723
public function set($key, $content, $expiry = 0)
    {
        $cacheObj = new \stdClass();

        if (!is_string($content)) {
            $content = serialize($content);
        }

        $cacheObj->content = $content;

        if (!$expiry) {
            // If no expiry specified, set to 'Never' expire timestamp (+10 years)
            $cacheObj->expiryTimestamp = time() + 315360000;
        } elseif ($expiry > 2592000) {
            // For value greater than 30 days, interpret as timestamp
            $cacheObj->expiryTimestamp = $expiry;
        } else {
            // Else, interpret as number of seconds
            $cacheObj->expiryTimestamp = time() + $expiry;
        }

        // Do not save if cache has already expired
        if ($cacheObj->expiryTimestamp < time()) {
            $this->delete($key);

            return false;
        }

        $cacheFileData = json_encode($cacheObj);

        if ($this->config['gzipCompression']) {
            $cacheFileData = gzcompress($cacheFileData);
        }

        $filePath = $this->getFilePathFromKey($key);
        $result = file_put_contents($filePath, $cacheFileData);

        return $result ? true : false;
    }
1327036
public function set($key, $val, $expire = 0)
    {
        if (!is_numeric($val)) {
            $val = json_encode($val);
        }

        if ($expire) {
            return $this->redis->setex($key, $expire, $val);
        }

        return $this->redis->set($key, $val);
    }
1308219
public function set($key, $value, $expire = 600) {
        $this->redis->setex($this->formatKey($key), $expire, $this->formatValue($value));
    }
530601
public function replace($key, $value, $expiration = 0)
    {
        return $this->memcached ? $this->memcached->replace($key, $value, $expiration) : false;
    }
1095174
public function set(string $key, string $value, int $expire): bool {
		return ($expire === -1) ? $this->driver->set($key, $value) : $this->driver->setex($key, $expire, $value);
	}
667477
public function set($key,$value,$expired){
		$mc=$this->getMemcache();
		if(empty($mc))return false;
		$this->queries_set_count++;
		return $mc->set($key,$value,false,$expired);
		}
687397
private function setCache(
        string $key, $value, ?int $expires
    ): void {
        $cache = $this->client->getItem($key);
        $cache->set($value);
        $cache->expiresAfter($expires);
        $this->client->save($cache);
    }
159317
public function set($name, $value, $expire = null) {
        N('cache_write',1);
        if(is_null($expire)) {
            $expire  =  $this->options['expire'];
        }
        $name   =   $this->options['prefix'].$name;
        if($result = apc_store($name, $value, $expire)) {
            if($this->options['length']>0) {
                // 记录缓存队列
                $this->queue($name);
            }
        }
        return $result;
     }
761904
public static function set(string $key, $value = null, int $expiration = 0): ?Cache
    {
        if (!self::$instance) {
            return null;
        }

        self::$instance->engine->set($key, $value, $expiration);

        return self::$instance;
    }
918586
public function cache($key=true,$expire=null,$type=''){
        // 增加快捷调用方式 cache(10) 等同于 cache(true, 10)
        if(is_numeric($key) && is_null($expire)){
            $expire = $key;
            $key    = true;
        }
        if(false !== $key)
            $this->options['cache']  =  array('key'=>$key,'expire'=>$expire,'type'=>$type);
        return $this;
    }
1300883
public function set($key, $value, $expire = 0)
    {
        // 如果expire为0时，设为长期有效。
        if ($expire != 0) {
            $expire = time() + $expire;
        } else {
            $expire = time() * 2;
        }

        $value = '<?php exit;?>' . $expire . serialize($value);

        // 检查目录可写否
        $cachedir = APP_PATH . '/' . Config::get("cache_dir");
        if (!is_writeable($cachedir)) {
            \show_error('ERROR: ' . $cachedir . ' is not writeable!');
        }

        return file_put_contents($this->_filename($key), $value);
    }
683428
private function setItem($key, $value, $time, $expire)
    {
        $cache_file = $this->createCacheFile($key);
        if ($cache_file === false) {
            return false;
        }

        $cache_data = array('data' => $value, 'time' => $time, 'expire' => $expire);
        $cache_data = json_encode($cache_data);

        $put_result = file_put_contents($cache_file, $cache_data);
        if ($put_result === false) {
            return false;
        }

        return true;
    }
348219
public function setValAndExpire($key, $value, $expire = 86400) {
		ini_set('session.gc_maxlifetime', $expire);
		session_set_cookie_params($expire);
		if(!isset($_SESSION)){
			session_start();
		}
		$_SESSION[$key] = $value;
	}
1168384
private function storeValueInCache($key, $value, $expiration = null)
    {
        $this->cache[$key] = new MemcacheObject($key, serialize($value), $this->normalizeExpirationTime($expiration));
    }
233344
public function set($key, $value, $expiration = 0)
    {
        $this->cache->save($key, $value, $expiration);
    }
1032496
public function set($key, $value, $expiration = 300) {

		if(false === is_string($key) && false === is_array($key)) {
   			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($key)), E_USER_ERROR);
   		}

   		if(0 === strlen($key)) {
   			return trigger_error(sprintf('Argument 1 passed to %s() may not be an empty string', __METHOD__), E_USER_ERROR);
   		}
   		
		$this -> expire($key);
		apcu_add($key, $value, $expiration);

		return $this;
	}