redis = new \Redis(); //docker redis1 6379 $this->redis->connect('127.0.0.1', 6379); $this->redis->auth("qwe110110"); $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) { $this->redis->get($key); //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 clear() { $keys = $this->redis->keys("*"); foreach ($keys as $key => $value) { $this->redis->del($value); } return true; //throw new InvalidArgumentException($error); } public function getMultiple($keys, $default = null) { $values = []; foreach ($keys as $key => $value) { $values[$key] = $this->redis->get($value); } return $values; //throw new InvalidArgumentException($error); } public function setMultiple($values, $ttl = null) { foreach ($values as $key => $value) { $this->redis->set($key, $value); } return true; //throw new InvalidArgumentException($error); } public function deleteMultiple($keys) { foreach ($keys as $key => $value) { $this->redis->del($key); } return true; //$error = ""; //throw new InvalidArgumentException($error); } public function has($key) { return $this->redis->exists($key); //throw new InvalidArgumentException($error); } }