Skip to content

Commit

Permalink
Make key prefix configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Christiansen committed Jan 19, 2015
1 parent ad8e999 commit e888dec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
5 changes: 4 additions & 1 deletion config-templates/module_redis.php
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'
);
25 changes: 19 additions & 6 deletions lib/Store/Redis.php
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
}

Expand All @@ -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);
Expand All @@ -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)) {
Expand All @@ -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);
}
}

0 comments on commit e888dec

Please sign in to comment.