redis = Redis::class; $this->prefix = $prefix; return $this; } /** * 设置缓存 * @param $key * @param $value * @param int $expire * @return true */ public function set($key, $value, int $expire = 0): true { $this->redis::set($this->prefix . $key, $value); if ($expire > 0) { $this->redis::expire($this->prefix . $key, $expire); } return true; } /** * 累加 * @param $key * @param int $value * @param int $expire * @return true */ public function incr($key, int $value = 1, int $expire = 0): true { $this->redis::incr($this->prefix . $key, $value); if ($expire > 0) { $this->redis::expire($this->prefix . $key, $expire); } return true; } /** * 获取缓存 * * @param $key * @return mixed */ public function get($key): mixed { return $this->redis::get($this->prefix . $key); } /** * 删除缓存 * @param $key * @return bool */ public function del($key): bool { return $this->redis::del($this->prefix . $key); } }