-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jacob Christiansen
committed
Jan 19, 2015
1 parent
ad8e999
commit e888dec
Showing
2 changed files
with
23 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
<?php | ||
$config = array ( | ||
'host' => 'tcp://localhost:6379' | ||
// Redis server | ||
'host' => 'tcp://localhost:6379', | ||
// Key prefix | ||
'prefix' => 'simplaSAMLphp' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
<?php | ||
/** | ||
* Redis store for simpleSAMLphp | ||
* | ||
* This store uses the Redis document store to store data from simpleSAMLphp. | ||
* It implements the simpleSAMLphp datastore API, for easy integration with | ||
* other parts of simpleSAMLphp. | ||
* | ||
* @author Jacob Christiansen [email protected] | ||
* @copyright 2015 Colourbox ApS | ||
* @license http://opensource.org/licenses/MIT MIT-license | ||
*/ | ||
class sspmod_redis_Store_Redis extends SimpleSAML_Store | ||
{ | ||
protected function __construct() | ||
{ | ||
$config = SimpleSAML_Configuration::getConfig('module_redis.php'); | ||
$host = $config->getString('host', 'localhost'); | ||
$this->redis = new Predis\Client($host); | ||
$redisConfig = SimpleSAML_Configuration::getConfig('module_redis.php'); | ||
$globalConfig = SimpleSAML_Configuration::getConfig(); | ||
|
||
$this->redis = new Predis\Client($redisConfig->getString('host', 'localhost')); | ||
$this->prefix = $redisConfig->getString('prefix', 'simpleSAMLphp'); | ||
$this->lifeTime = $globalConfig->getInteger('session.duration', 28800); // Default 8 hours | ||
} | ||
|
||
|
@@ -18,7 +31,7 @@ protected function __construct() | |
*/ | ||
public function get($type, $key) | ||
{ | ||
$redisKey = "simpleSAMLphp.$type.$key"; | ||
$redisKey = "{$this->prefix}.$type.$key"; | ||
$value = $this->redis->get($redisKey); | ||
|
||
return unserialize($value); | ||
|
@@ -37,7 +50,7 @@ public function get($type, $key) | |
*/ | ||
public function set($type, $key, $value, $expire = null) | ||
{ | ||
$redisKey = "simpleSAMLphp.$type.$key"; | ||
$redisKey = "{$this->prefix}.$type.$key"; | ||
$this->redis->set($redisKey, serialize($value)); | ||
|
||
if (is_null($expire)) { | ||
|
@@ -54,7 +67,7 @@ public function set($type, $key, $value, $expire = null) | |
*/ | ||
public function delete($type, $key) | ||
{ | ||
$redisKey = "simpleSAMLphp.$type.$key"; | ||
$redisKey = "{$this->prefix}.$type.$key"; | ||
$this->redis->del($redisKey); | ||
} | ||
} |