ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SimpleSAML\Store\Redis Class Reference
+ Inheritance diagram for SimpleSAML\Store\Redis:
+ Collaboration diagram for SimpleSAML\Store\Redis:

Public Member Functions

 __construct ($redis=null)
 Initialize the Redis data store. More...
 
 __destruct ()
 Deconstruct the Redis data store. More...
 
 get ($type, $key)
 Retrieve a value from the data store. More...
 
 set ($type, $key, $value, $expire=null)
 Save a value in the data store. More...
 
 delete ($type, $key)
 Delete an entry from the data store. More...
 
- Public Member Functions inherited from SimpleSAML\Store
 get ($type, $key)
 Retrieve a value from the data store. More...
 
 set ($type, $key, $value, $expire=null)
 Save a value to the data store. More...
 
 delete ($type, $key)
 Delete a value from the data store. More...
 

Data Fields

 $redis
 

Additional Inherited Members

- Static Public Member Functions inherited from SimpleSAML\Store
static getInstance ()
 Retrieve our singleton instance. More...
 

Detailed Description

Definition at line 13 of file Redis.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleSAML\Store\Redis::__construct (   $redis = null)

Initialize the Redis data store.

Definition at line 20 of file Redis.php.

References $config, and SimpleSAML\Store\Redis\$redis.

21  {
22  assert($redis === null || is_subclass_of($redis, 'Predis\\Client'));
23 
24  if (!class_exists('\Predis\Client')) {
25  throw new \SimpleSAML\Error\CriticalConfigurationError('predis/predis is not available.');
26  }
27 
28  if ($redis === null) {
29  $config = Configuration::getInstance();
30 
31  $host = $config->getString('store.redis.host', 'localhost');
32  $port = $config->getInteger('store.redis.port', 6379);
33  $prefix = $config->getString('store.redis.prefix', 'SimpleSAMLphp');
34 
35  $redis = new \Predis\Client(
36  array(
37  'scheme' => 'tcp',
38  'host' => $host,
39  'port' => $port,
40  ),
41  array(
42  'prefix' => $prefix,
43  )
44  );
45  }
46 
47  $this->redis = $redis;
48  }
$config
Definition: bootstrap.php:15

◆ __destruct()

SimpleSAML\Store\Redis::__destruct ( )

Deconstruct the Redis data store.

Definition at line 53 of file Redis.php.

54  {
55  if (method_exists($this->redis, 'disconnect')) {
56  $this->redis->disconnect();
57  }
58  }

Member Function Documentation

◆ delete()

SimpleSAML\Store\Redis::delete (   $type,
  $key 
)

Delete an entry from the data store.

Parameters
string$typeThe type of the data
string$keyThe key to delete.

Definition at line 112 of file Redis.php.

References $type.

113  {
114  assert(is_string($type));
115  assert(is_string($key));
116 
117  $this->redis->del("{$type}.{$key}");
118  }
$type
$key
Definition: croninfo.php:18

◆ get()

SimpleSAML\Store\Redis::get (   $type,
  $key 
)

Retrieve a value from the data store.

Parameters
string$typeThe type of the data.
string$keyThe key to retrieve.
Returns
mixed|null The value associated with that key, or null if there's no such key.

Definition at line 68 of file Redis.php.

References $key, $result, and $type.

69  {
70  assert(is_string($type));
71  assert(is_string($key));
72 
73  $result = $this->redis->get("{$type}.{$key}");
74 
75  if ($result === false || $result === null) {
76  return null;
77  }
78 
79  return unserialize($result);
80  }
$result
$type
$key
Definition: croninfo.php:18

◆ set()

SimpleSAML\Store\Redis::set (   $type,
  $key,
  $value,
  $expire = null 
)

Save a value in the data store.

Parameters
string$typeThe type of the data.
string$keyThe key to insert.
mixed$valueThe value itself.
int | null$expireThe expiration time (unix timestamp), or null if it never expires.

Definition at line 90 of file Redis.php.

References $type.

91  {
92  assert(is_string($type));
93  assert(is_string($key));
94  assert($expire === null || (is_int($expire) && $expire > 2592000));
95 
96  $serialized = serialize($value);
97 
98  if ($expire === null) {
99  $this->redis->set("{$type}.{$key}", $serialized);
100  } else {
101  // setex expire time is in seconds (not unix timestamp)
102  $this->redis->setex("{$type}.{$key}", $expire - time(), $serialized);
103  }
104  }
$expire
Definition: saml2-acs.php:140
$type
$key
Definition: croninfo.php:18

Field Documentation

◆ $redis

SimpleSAML\Store\Redis::$redis

Definition at line 15 of file Redis.php.

Referenced by SimpleSAML\Store\Redis\__construct().


The documentation for this class was generated from the following file: