From 9dfc7127edecb57145a9d3b22a1f61732dfc47b6 Mon Sep 17 00:00:00 2001 From: zyimm Date: Tue, 5 Sep 2023 17:38:06 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=BA=E8=AE=BE=E8=AE=A1=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F-=E5=B7=A5=E5=8E=82=E6=A8=A1=E5=BC=8F=E6=9B=B4?= =?UTF-8?q?=E6=96=B0redis=E4=BD=BF=E7=94=A8=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../编程/设计模式/行为模式/factory-method.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/_posts/编程/设计模式/行为模式/factory-method.md b/_posts/编程/设计模式/行为模式/factory-method.md index 852a8aa..ed6802c 100644 --- a/_posts/编程/设计模式/行为模式/factory-method.md +++ b/_posts/编程/设计模式/行为模式/factory-method.md @@ -121,7 +121,7 @@ class Cache **😸2.编写各个类型cache子类** ```php - +// redis class Redis extends Cache { @@ -137,18 +137,25 @@ class Redis extends Cache protected function connect() { //根据Config进行缓存连接 - $redis = new \Redis(); + $this->redis = new \Redis(); // 连接 Redis 服务器 - $redis->connect($this->config->getHost() , $this->config->getPort() ?? 6379); + $this->redis->connect($this->config->getHost() , $this->config->getPort() ?? 6379); // 可选:设置 Redis 密码 - $redis->auth($this->config->getPassword()); + $this->redis->auth($this->config->getPassword()); } + + // 动态调用redis 方法 + public function __call($method, ...$arguments) { + call_user_func([$this->redis, $method], ...$arguments); + } + + } - +//内存 class Memory extends Cache { @@ -162,6 +169,7 @@ class Memory extends Cache } +//文件 class File extends Cache { @@ -171,7 +179,6 @@ class File extends Cache { parent::__construct(Config $config); - }