Skip to content

Commit e888dec

Browse files
author
Jacob Christiansen
committed
Make key prefix configurable
1 parent ad8e999 commit e888dec

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

config-templates/module_redis.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
22
$config = array (
3-
'host' => 'tcp://localhost:6379'
3+
// Redis server
4+
'host' => 'tcp://localhost:6379',
5+
// Key prefix
6+
'prefix' => 'simplaSAMLphp'
47
);

lib/Store/Redis.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
<?php
2+
/**
3+
* Redis store for simpleSAMLphp
4+
*
5+
* This store uses the Redis document store to store data from simpleSAMLphp.
6+
* It implements the simpleSAMLphp datastore API, for easy integration with
7+
* other parts of simpleSAMLphp.
8+
*
9+
* @author Jacob Christiansen [email protected]
10+
* @copyright 2015 Colourbox ApS
11+
* @license http://opensource.org/licenses/MIT MIT-license
12+
*/
213
class sspmod_redis_Store_Redis extends SimpleSAML_Store
314
{
415
protected function __construct()
516
{
6-
$config = SimpleSAML_Configuration::getConfig('module_redis.php');
7-
$host = $config->getString('host', 'localhost');
8-
$this->redis = new Predis\Client($host);
17+
$redisConfig = SimpleSAML_Configuration::getConfig('module_redis.php');
18+
$globalConfig = SimpleSAML_Configuration::getConfig();
19+
20+
$this->redis = new Predis\Client($redisConfig->getString('host', 'localhost'));
21+
$this->prefix = $redisConfig->getString('prefix', 'simpleSAMLphp');
922
$this->lifeTime = $globalConfig->getInteger('session.duration', 28800); // Default 8 hours
1023
}
1124

@@ -18,7 +31,7 @@ protected function __construct()
1831
*/
1932
public function get($type, $key)
2033
{
21-
$redisKey = "simpleSAMLphp.$type.$key";
34+
$redisKey = "{$this->prefix}.$type.$key";
2235
$value = $this->redis->get($redisKey);
2336

2437
return unserialize($value);
@@ -37,7 +50,7 @@ public function get($type, $key)
3750
*/
3851
public function set($type, $key, $value, $expire = null)
3952
{
40-
$redisKey = "simpleSAMLphp.$type.$key";
53+
$redisKey = "{$this->prefix}.$type.$key";
4154
$this->redis->set($redisKey, serialize($value));
4255

4356
if (is_null($expire)) {
@@ -54,7 +67,7 @@ public function set($type, $key, $value, $expire = null)
5467
*/
5568
public function delete($type, $key)
5669
{
57-
$redisKey = "simpleSAMLphp.$type.$key";
70+
$redisKey = "{$this->prefix}.$type.$key";
5871
$this->redis->del($redisKey);
5972
}
6073
}

0 commit comments

Comments
 (0)