From 34bd9f4da9f493435e1d5ca3a3ae16d7051a0b75 Mon Sep 17 00:00:00 2001 From: Bournwog Date: Tue, 17 Jun 2025 20:52:52 +0300 Subject: [PATCH 1/2] Update xPDORedisCache.php --- src/xPDO/Cache/xPDORedisCache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xPDO/Cache/xPDORedisCache.php b/src/xPDO/Cache/xPDORedisCache.php index a24db952..7c8a1965 100644 --- a/src/xPDO/Cache/xPDORedisCache.php +++ b/src/xPDO/Cache/xPDORedisCache.php @@ -48,7 +48,7 @@ public function __construct(& $xpdo, $options = array()) { public function add($key, $var, $expire= 0, $options= array()) { $added= false; if(!$this->redis->exists($this->getCacheKey($key))){ - $added=$this->redis->set($this->getCacheKey($key),$var,$expire); + $added=$this->set($key, $var, $expire); } return $added; } @@ -65,7 +65,7 @@ public function set($key, $var, $expire= 0, $options= array()) { public function replace($key, $var, $expire= 0, $options= array()) { $replaced=false; if($this->redis->exists($this->getCacheKey($key))){ - $replaced=$this->redis->set($this->getCacheKey($key),$var,$expire); + $replaced=$this->set($key, $var, $expire); } return $replaced; } From 9f64c718e9c33471344777b3fe5a0b7a77f6a67c Mon Sep 17 00:00:00 2001 From: Jason Coward Date: Wed, 1 Oct 2025 14:10:59 -0600 Subject: [PATCH 2/2] Update formatting --- src/xPDO/Cache/xPDORedisCache.php | 87 ++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 30 deletions(-) diff --git a/src/xPDO/Cache/xPDORedisCache.php b/src/xPDO/Cache/xPDORedisCache.php index 7c8a1965..81722103 100644 --- a/src/xPDO/Cache/xPDORedisCache.php +++ b/src/xPDO/Cache/xPDORedisCache.php @@ -7,7 +7,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ + namespace xPDO\Cache; + use xPDO\xPDO; use Redis; @@ -18,74 +20,99 @@ * * @package xPDO\Cache */ -class xPDORedisCache extends xPDOCache { +class xPDORedisCache extends xPDOCache +{ protected $redis = null; - public function __construct(& $xpdo, $options = array()) { - parent :: __construct($xpdo, $options); + public function __construct(&$xpdo, $options = []) + { + parent:: __construct($xpdo, $options); if (class_exists('Redis', true)) { - $this->redis= new Redis(); + $this->redis = new Redis(); if ($this->redis) { - $server = explode(':', $this->getOption($this->key . '_redis_server', $options, $this->getOption('redis_server', $options, 'localhost:6379'))); - if($this->redis->pconnect($server[0], (integer) $server[1])){ - $redis_auth=$this->getOption('redis_auth', $options, ''); - if(!empty($redis_auth)){ - $this->redis->auth($redis_auth); + $server = explode( + ':', + $this->getOption( + $this->key . '_redis_server', + $options, + $this->getOption('redis_server', $options, 'localhost:6379') + ) + ); + if ($this->redis->pconnect($server[0], (integer)$server[1])) { + $redis_auth = $this->getOption('redis_auth', $options, ''); + if (!empty($redis_auth)) { + $this->redis->auth($redis_auth); } $this->redis->select((integer)$this->getOption('redis_db', $options, 0)); $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); - $this->initialized = true; - } + $this->initialized = true; + } } else { $this->redis = null; - $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDORedisCache[{$this->key}]: Error creating redis provider for server(s): " . $this->getOption($this->key . '_redisd_server', $options, $this->getOption('redisd_server', $options, 'localhost:6379'))); + $this->xpdo->log( + xPDO::LOG_LEVEL_ERROR, + "xPDORedisCache[{$this->key}]: Error creating redis provider for server(s): " . $this->getOption( + $this->key . '_redisd_server', + $options, + $this->getOption('redisd_server', $options, 'localhost:6379') + ) + ); } } else { - $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDORedisCache[{$this->key}]: Error creating redis provider; xPDORedisCache requires the PHP redis extension."); + $this->xpdo->log( + xPDO::LOG_LEVEL_ERROR, + "xPDORedisCache[{$this->key}]: Error creating redis provider; xPDORedisCache requires the PHP redis extension." + ); } } - public function add($key, $var, $expire= 0, $options= array()) { - $added= false; - if(!$this->redis->exists($this->getCacheKey($key))){ - $added=$this->set($key, $var, $expire); + public function add($key, $var, $expire = 0, $options = []) + { + $added = false; + if (!$this->redis->exists($this->getCacheKey($key))) { + $added = $this->set($key, $var, $expire); } return $added; } - public function set($key, $var, $expire= 0, $options= array()) { + public function set($key, $var, $expire = 0, $options = []) + { if ($expire === 0) { - $set = $this->redis->set($this->getCacheKey($key),$var); + $set = $this->redis->set($this->getCacheKey($key), $var); } else { - $set = $this->redis->set($this->getCacheKey($key),$var,$expire); + $set = $this->redis->set($this->getCacheKey($key), $var, $expire); } return $set; } - public function replace($key, $var, $expire= 0, $options= array()) { - $replaced=false; - if($this->redis->exists($this->getCacheKey($key))){ - $replaced=$this->set($key, $var, $expire); + public function replace($key, $var, $expire = 0, $options = []) + { + $replaced = false; + if ($this->redis->exists($this->getCacheKey($key))) { + $replaced = $this->set($key, $var, $expire); } return $replaced; } - public function delete($key, $options= array()) { + public function delete($key, $options = []) + { if ($this->getOption(xPDO::OPT_CACHE_MULTIPLE_OBJECT_DELETE, $options, false)) { - $deleted= $this->flush($options); + $deleted = $this->flush($options); } else { - $deleted= $this->redis->delete($this->getCacheKey($key)); + $deleted = $this->redis->delete($this->getCacheKey($key)); } return $deleted; } - public function get($key, $options= array()) { - $value= $this->redis->get($this->getCacheKey($key)); + public function get($key, $options = []) + { + $value = $this->redis->get($this->getCacheKey($key)); return $value; } - public function flush($options= array()) { + public function flush($options = []) + { return $this->redis->flushDb(); } }