Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Redis.php
Go to the documentation of this file.
1 <?php
7 
8 use Cm\RedisSession\Handler\ConfigInterface;
9 use Cm\RedisSession\Handler\LoggerInterface;
10 use Cm\RedisSession\ConnectionFailedException;
11 use Cm\RedisSession\ConcurrentConnectionsExceededException;
16 
17 class Redis implements \SessionHandlerInterface
18 {
22  private $config;
23 
27  private $logger;
28 
32  private $filesystem;
33 
37  private $connection;
38 
45  public function __construct(ConfigInterface $config, LoggerInterface $logger, Filesystem $filesystem)
46  {
47  $this->config = $config;
48  $this->logger = $logger;
49  $this->filesystem = $filesystem;
50  }
51 
58  private function getConnection()
59  {
60  $pid = getmypid();
61  if (!isset($this->connection[$pid])) {
62  try {
63  $this->connection[$pid] = new \Cm\RedisSession\Handler($this->config, $this->logger);
64  } catch (ConnectionFailedException $e) {
65  throw new SessionException(new Phrase($e->getMessage()));
66  }
67  }
68  return $this->connection[$pid];
69  }
70 
79  public function open($savePath, $sessionName)
80  {
81  return $this->getConnection()->open($savePath, $sessionName);
82  }
83 
92  public function read($sessionId)
93  {
94  try {
95  return $this->getConnection()->read($sessionId);
96  } catch (ConcurrentConnectionsExceededException $e) {
97  require $this->filesystem->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath('errors/503.php');
98  }
99  }
100 
109  public function write($sessionId, $sessionData)
110  {
111  return $this->getConnection()->write($sessionId, $sessionData);
112  }
113 
121  public function destroy($sessionId)
122  {
123  return $this->getConnection()->destroy($sessionId);
124  }
125 
132  public function close()
133  {
134  return $this->getConnection()->close();
135  }
136 
145  public function gc($maxLifeTime)
146  {
147  return $this->getConnection()->gc($maxLifeTime);
148  }
149 
156  public function getFailedLockAttempts()
157  {
158  return $this->getConnection()->getFailedLockAttempts();
159  }
160 }
$config
Definition: fraud_order.php:17
$logger
__construct(ConfigInterface $config, LoggerInterface $logger, Filesystem $filesystem)
Definition: Redis.php:45
write($sessionId, $sessionData)
Definition: Redis.php:109
$filesystem
open($savePath, $sessionName)
Definition: Redis.php:79