-
Notifications
You must be signed in to change notification settings - Fork 0
/
RedisStorage.php
37 lines (31 loc) · 966 Bytes
/
RedisStorage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
//Backend to store Session in Redis.
include_once "SessionInterface.php"; //Interface for the Backend Operation
class RedisStorage implements SessionInterface
{
private $redisHost;
private $redisPort;
public function __construct()
{
$this->redisHost = "127.0.0.1"; // Redis host
$this->redisPort = 6379; // Redis port
}
public function storeSession($name, $content)
{
$redis = new Redis();
$redis->pconnect($this->redisHost, $this->redisHost);
$redis->setEx($name, 300, $content);
}
public function updateSession($name, $content)
{
$redis = new Redis();
$redis->pconnect($this->redisHost, $this->redisHost);
$redis->setEx($name, 300, $content);
}
public function readSession($name)
{
$redis = new Redis();
$redis->pconnect($this->redisHost, $this->redisHost);
return $redis->get($name);
}
}