redis = new \Redis(); //docker redis1 6379 $this->redis->connect('127.0.0.1', 6379); //$this->redis->auth("qwe110110"); $this->redis->auth("zhonghui0123"); $this->redis->select("1"); //选择1号数据库 默认0号 if (!$this->redis->ping()) { $error = "connect error"; throw new InvalidArgumentException($error); //throw new \Exception("链接失败"); } } public function get($key, $default = null) { $value = $this->redis->get($key); return $value; //throw new InvalidArgumentException($error); } public function set($key, $value, $ttl = null) { $this->redis->set($key, $value); //throw new InvalidArgumentException($error); return true; } public function delete($key) { $this->redis->del($key); return true; //throw new InvalidArgumentException($error); } public function has($key) { return $this->redis->exists($key); //throw new InvalidArgumentException($error); } }