From d5e267e2416f7be859546afc997267cce45bdcc4 Mon Sep 17 00:00:00 2001 From: ChoOo7 Date: Thu, 10 Mar 2016 16:22:11 +0100 Subject: [PATCH 1/3] Gestion de l'authentification depuis les options. But : gestion de Azure Redis Cache --- lib/Redis/DualRedis.php | 7 +++++++ lib/Store/Redis.php | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/lib/Redis/DualRedis.php b/lib/Redis/DualRedis.php index b7386da..c4790d8 100644 --- a/lib/Redis/DualRedis.php +++ b/lib/Redis/DualRedis.php @@ -22,6 +22,13 @@ public function set($key, $value) $this->newHost->set($key, $value); } + + public function auth($key) + { + $this->newHost->auth($key); + $this->oldHost->auth($key); + } + public function keys($pattern) { return array_unique(array_merge( diff --git a/lib/Store/Redis.php b/lib/Store/Redis.php index fd19ea7..d5469ef 100644 --- a/lib/Store/Redis.php +++ b/lib/Store/Redis.php @@ -28,6 +28,10 @@ public function __construct() new Predis\Client($redisConfig->getString('new_host')) ); } + if($auth = $redisConfig->getString('auth', '')) + { + $this->redis->auth($auth); + } $this->prefix = $redisConfig->getString('prefix', 'simpleSAMLphp'); $this->lifeTime = $redisConfig->getInteger('lifetime', 28800); // 8 hours } From 88ffefb481200febdcc7fbf72922c93625d4e9c1 Mon Sep 17 00:00:00 2001 From: Simon Minotto Date: Tue, 21 Mar 2017 15:49:23 +0100 Subject: [PATCH 2/3] Redis - gestion connection --- lib/Store/Redis.php | 53 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/lib/Store/Redis.php b/lib/Store/Redis.php index b9e16e8..5032bc1 100644 --- a/lib/Store/Redis.php +++ b/lib/Store/Redis.php @@ -18,24 +18,31 @@ class sspmod_redis_Store_Redis extends SimpleSAML_Store public function __construct() { - $config = SimpleSAML_Configuration::getConfig('module_redis.php'); + $redisConfig = SimpleSAML_Configuration::getConfig('module_redis.php'); - if ($config->hasValue('oldHost')) { - $oldHost = $config->getValue('oldHost'); + if ($redisConfig->hasValue('oldHost')) { + $oldHost = $redisConfig->getValue('oldHost'); $this->redis = new sspmod_redis_Redis_DualRedis( new Predis\Client($oldHost['parameters'], $oldHost['options']), - new Predis\Client($config->getValue('parameters'), $config->getValue('options')) + new Predis\Client($redisConfig->getValue('parameters'), $redisConfig->getValue('options')) ); } else { - $this->redis = new Predis\Client($config->getValue('parameters'), $config->getValue('options')); + $this->redis = new Predis\Client($redisConfig->getValue('parameters'), $redisConfig->getValue('options')); } - + + $this->auth(); + + $this->prefix = $redisConfig->getString('prefix', 'simpleSAMLphp'); + $this->lifeTime = $redisConfig->getInteger('lifetime', 28800); // 8 hours + } + + protected function auth() + { + $redisConfig = SimpleSAML_Configuration::getConfig('module_redis.php'); if($auth = $redisConfig->getString('auth', '')) { $this->redis->auth($auth); } - $this->prefix = $redisConfig->getString('prefix', 'simpleSAMLphp'); - $this->lifeTime = $redisConfig->getInteger('lifetime', 28800); // 8 hours } /** @@ -71,12 +78,23 @@ public function get($type, $key) public function set($type, $key, $value, $expire = null) { $redisKey = "{$this->prefix}.$type.$key"; - $this->redis->set($redisKey, serialize($value)); - - if (is_null($expire)) { + if (is_null($expire)) + { $expire = time() + $this->lifeTime; } - $this->redis->expireat($redisKey, $expire); + + try + { + $this->redis->set($redisKey, serialize($value)); + $this->redis->expireat($redisKey, $expire); + } + catch(\ Exception $e) + { + //on shutdown sometime the auth is not set ! + $this->auth(); + $this->redis->set($redisKey, serialize($value)); + $this->redis->expireat($redisKey, $expire); + } } /** @@ -88,6 +106,15 @@ public function set($type, $key, $value, $expire = null) public function delete($type, $key) { $redisKey = "{$this->prefix}.$type.$key"; - $this->redis->del($redisKey); + try + { + $this->redis->del($redisKey); + } + catch(\ Exception $e) + { + //on shutdown sometime the auth is not set ! + $this->auth(); + $this->redis->del($redisKey); + } } } From 4d183aac52d693e5dfc64076d763c43bb01a72e3 Mon Sep 17 00:00:00 2001 From: Simon Minotto Date: Tue, 21 Mar 2017 15:58:05 +0100 Subject: [PATCH 3/3] Redis - gestion connection --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 16f5176..83c2086 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "wiki": "https://github.com/ColourboxDevelopment/simplesamlphp-module-redis/wiki" }, "require": { - "php": "^5.4", + "php": ">=5.4", "predis/predis": "~1.0", "simplesamlphp/composer-module-installer": "^1.1" },