Skip to content

Commit abae0e0

Browse files
committed
MAGETWO-93998: [Forwardport] Run Product Price reindex in multithread mode with Redis
1 parent ba68d15 commit abae0e0

File tree

1 file changed

+115
-7
lines changed
  • lib/internal/Magento/Framework/Session/SaveHandler

1 file changed

+115
-7
lines changed

lib/internal/Magento/Framework/Session/SaveHandler/Redis.php

Lines changed: 115 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,28 @@
1414
use Magento\Framework\Filesystem;
1515
use Magento\Framework\App\Filesystem\DirectoryList;
1616

17-
class Redis extends \Cm\RedisSession\Handler
17+
class Redis implements \SessionHandlerInterface
1818
{
19+
/**
20+
* @var ConfigInterface
21+
*/
22+
private $config;
23+
24+
/**
25+
* @var LoggerInterface
26+
*/
27+
private $logger;
28+
1929
/**
2030
* @var Filesystem
2131
*/
2232
private $filesystem;
2333

34+
/**
35+
* @var \Cm\RedisSession\Handler[]
36+
*/
37+
private $connection;
38+
2439
/**
2540
* @param ConfigInterface $config
2641
* @param LoggerInterface $logger
@@ -29,23 +44,116 @@ class Redis extends \Cm\RedisSession\Handler
2944
*/
3045
public function __construct(ConfigInterface $config, LoggerInterface $logger, Filesystem $filesystem)
3146
{
47+
$this->config = $config;
48+
$this->logger = $logger;
3249
$this->filesystem = $filesystem;
33-
try {
34-
parent::__construct($config, $logger);
35-
} catch (ConnectionFailedException $e) {
36-
throw new SessionException(new Phrase($e->getMessage()));
50+
}
51+
52+
/**
53+
* Get connection
54+
*
55+
* @return \Cm\RedisSession\Handler
56+
* @throws SessionException
57+
*/
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+
}
3767
}
68+
return $this->connection[$pid];
3869
}
3970

4071
/**
41-
* {@inheritdoc}
72+
* Open session
73+
*
74+
* @param string $savePath ignored
75+
* @param string $sessionName ignored
76+
* @return bool
77+
* @throws SessionException
78+
*/
79+
public function open($savePath, $sessionName)
80+
{
81+
return $this->getConnection()->open($savePath, $sessionName);
82+
}
83+
84+
/**
85+
* Fetch session data
86+
*
87+
* @param string $sessionId
88+
* @return string
89+
* @throws ConcurrentConnectionsExceededException
90+
* @throws SessionException
4291
*/
4392
public function read($sessionId)
4493
{
4594
try {
46-
return parent::read($sessionId);
95+
return $this->getConnection()->read($sessionId);
4796
} catch (ConcurrentConnectionsExceededException $e) {
4897
require $this->filesystem->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath('errors/503.php');
4998
}
5099
}
100+
101+
/**
102+
* Update session
103+
*
104+
* @param string $sessionId
105+
* @param string $sessionData
106+
* @return boolean
107+
* @throws SessionException
108+
*/
109+
public function write($sessionId, $sessionData)
110+
{
111+
return $this->getConnection()->write($sessionId, $sessionData);
112+
}
113+
114+
/**
115+
* Destroy session
116+
*
117+
* @param string $sessionId
118+
* @return boolean
119+
* @throws SessionException
120+
*/
121+
public function destroy($sessionId)
122+
{
123+
return $this->getConnection()->destroy($sessionId);
124+
}
125+
126+
/**
127+
* Overridden to prevent calling getLifeTime at shutdown
128+
*
129+
* @return bool
130+
* @throws SessionException
131+
*/
132+
public function close()
133+
{
134+
return $this->getConnection()->close();
135+
}
136+
137+
/**
138+
* Garbage collection
139+
*
140+
* @param int $maxLifeTime ignored
141+
* @return boolean
142+
* @throws SessionException
143+
*/
144+
public function gc($maxLifeTime)
145+
{
146+
return $this->getConnection()->gc($maxLifeTime);
147+
}
148+
149+
/**
150+
* Get the number of failed lock attempts
151+
*
152+
* @return int
153+
* @throws SessionException
154+
*/
155+
public function getFailedLockAttempts()
156+
{
157+
return $this->getConnection()->getFailedLockAttempts();
158+
}
51159
}

0 commit comments

Comments
 (0)