Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 1babe34

Browse files
author
Patrick McLain
committed
Update colinmollenhour/php-redis-session-abstract
* Update implementation of `Cm\RedisSession\Handler\ConfigInterface` * Add Redis Sentinel config options to `setup:config:set` command
1 parent fa906ed commit 1babe34

File tree

6 files changed

+172
-15
lines changed

6 files changed

+172
-15
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"colinmollenhour/cache-backend-file": "1.4",
3535
"colinmollenhour/cache-backend-redis": "1.10.2",
3636
"colinmollenhour/credis": "1.6",
37-
"colinmollenhour/php-redis-session-abstract": "~1.2.2",
37+
"colinmollenhour/php-redis-session-abstract": "~1.3.8",
3838
"composer/composer": "1.4.1",
3939
"magento/composer": "~1.2.0",
4040
"magento/magento-composer-installer": ">=0.1.11",
@@ -50,6 +50,7 @@
5050
"symfony/process": "~2.1",
5151
"tedivm/jshrink": "~1.1.0",
5252
"tubalmartin/cssmin": "4.1.0",
53+
"webonyx/graphql-php": "^0.11.1",
5354
"zendframework/zend-captcha": "^2.7.1",
5455
"zendframework/zend-code": "^3.1.0",
5556
"zendframework/zend-config": "^2.6.0",
@@ -75,8 +76,7 @@
7576
"zendframework/zend-text": "^2.6.0",
7677
"zendframework/zend-uri": "^2.5.1",
7778
"zendframework/zend-validator": "^2.6.0",
78-
"zendframework/zend-view": "^2.8.1",
79-
"webonyx/graphql-php": "^0.11.1"
79+
"zendframework/zend-view": "^2.8.1"
8080
},
8181
"require-dev": {
8282
"friendsofphp/php-cs-fixer": "~2.1.1",

composer.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ class Config implements \Cm\RedisSession\Handler\ConfigInterface
100100
*/
101101
const PARAM_BREAK_AFTER = 'session/redis/break_after';
102102

103+
/**
104+
* Configuration path for comma separated list of sentinel servers
105+
*/
106+
const PARAM_SENTINEL_SERVERS = 'session/redis/sentinel_servers';
107+
108+
/**
109+
* Configuration path for sentinel master
110+
*/
111+
const PARAM_SENTINEL_MASTER = 'session/redis/sentinel_master';
112+
113+
/**
114+
* Configuration path for verify sentinel master flag
115+
*/
116+
const PARAM_SENTINEL_VERIFY_MASTER = 'session/redis/sentinel_verify_master';
117+
118+
/**
119+
* Configuration path for number of sentinel connection retries
120+
*/
121+
const PARAM_SENTINEL_CONNECT_RETRIES = 'session/redis/sentinel_connect_retries';
122+
103123
/**
104124
* Cookie lifetime config path
105125
*/
@@ -115,6 +135,11 @@ class Config implements \Cm\RedisSession\Handler\ConfigInterface
115135
*/
116136
const SESSION_MAX_LIFETIME = 31536000;
117137

138+
/**
139+
* Try to break lock for at most this many seconds
140+
*/
141+
const DEFAULT_FAIL_AFTER = 15;
142+
118143
/**
119144
* Deployment config
120145
*
@@ -293,4 +318,44 @@ public function getLifetime()
293318
}
294319
return (int)$this->scopeConfig->getValue(self::XML_PATH_COOKIE_LIFETIME, StoreScopeInterface::SCOPE_STORE);
295320
}
321+
322+
/**
323+
* {@inheritdoc}
324+
*/
325+
public function getSentinelServers()
326+
{
327+
return $this->deploymentConfig->get(self::PARAM_SENTINEL_SERVERS);
328+
}
329+
330+
/**
331+
* {@inheritdoc}
332+
*/
333+
public function getSentinelMaster()
334+
{
335+
return $this->deploymentConfig->get(self::PARAM_SENTINEL_MASTER);
336+
}
337+
338+
/**
339+
* {@inheritdoc}
340+
*/
341+
public function getSentinelVerifyMaster()
342+
{
343+
return $this->deploymentConfig->get(self::PARAM_SENTINEL_VERIFY_MASTER);
344+
}
345+
346+
/**
347+
* {@inheritdoc}
348+
*/
349+
public function getSentinelConnectRetries()
350+
{
351+
return $this->deploymentConfig->get(self::PARAM_SENTINEL_CONNECT_RETRIES);
352+
}
353+
354+
/**
355+
* {@inheritdoc}
356+
*/
357+
public function getFailAfter()
358+
{
359+
return self::DEFAULT_FAIL_AFTER;
360+
}
296361
}

lib/internal/Magento/Framework/Session/Test/Unit/SaveHandler/Redis/ConfigTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,49 @@ public function testGetLifetimeFrontend()
246246
->willReturn($expectedLifetime);
247247
$this->assertEquals($this->config->getLifetime(), $expectedLifetime);
248248
}
249+
250+
public function testGetSentinelServers()
251+
{
252+
$expected = 'server-1,server-2';
253+
$this->deploymentConfigMock->expects($this->once())
254+
->method('get')
255+
->with(Config::PARAM_SENTINEL_SERVERS)
256+
->willReturn($expected);
257+
$this->assertEquals($expected, $this->config->getSentinelServers());
258+
}
259+
260+
public function testGetSentinelMaster()
261+
{
262+
$expected = 'master';
263+
$this->deploymentConfigMock->expects($this->once())
264+
->method('get')
265+
->with(Config::PARAM_SENTINEL_MASTER)
266+
->willReturn($expected);
267+
$this->assertEquals($this->config->getSentinelMaster(), $expected);
268+
}
269+
270+
public function testGetSentinelVerifyMaster()
271+
{
272+
$expected = '1';
273+
$this->deploymentConfigMock->expects($this->once())
274+
->method('get')
275+
->with(Config::PARAM_SENTINEL_VERIFY_MASTER)
276+
->willReturn($expected);
277+
$this->assertEquals($this->config->getSentinelVerifyMaster(), $expected);
278+
}
279+
280+
public function testGetSentinelConnectRetries()
281+
{
282+
$expected = '10';
283+
$this->deploymentConfigMock->expects($this->once())
284+
->method('get')
285+
->willReturn(Config::PARAM_SENTINEL_CONNECT_RETRIES)
286+
->willReturn($expected);
287+
$this->assertEquals($this->config->getSentinelConnectRetries(), $expected);
288+
}
289+
290+
public function testGetFailAfter()
291+
{
292+
$this->assertEquals($this->config->getFailAfter(), Config::DEFAULT_FAIL_AFTER);
293+
}
249294
}

setup/src/Magento/Setup/Model/ConfigOptionsList/Session.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class Session implements ConfigOptionsListInterface
3737
const INPUT_KEY_SESSION_REDIS_DISABLE_LOCKING = 'session-save-redis-disable-locking';
3838
const INPUT_KEY_SESSION_REDIS_MIN_LIFETIME = 'session-save-redis-min-lifetime';
3939
const INPUT_KEY_SESSION_REDIS_MAX_LIFETIME = 'session-save-redis-max-lifetime';
40+
const INPUT_KEY_SESSION_REDIS_SENTINEL_SERVERS = 'session-save-redis-sentinel-servers';
41+
const INPUT_KEY_SESSION_REDIS_SENTINEL_MASTER = 'session-save-redis-sentinel-master';
42+
const INPUT_KEY_SESSION_REDIS_SENTINEL_VERIFY_MASTER = 'session-save-redis-sentinel-verify-master';
43+
const INPUT_KEY_SESSION_REDIS_SENTINEL_CONNECT_RETRIES = 'session-save-redis-sentinel-connect-retires';
4044

4145
const CONFIG_PATH_SESSION_REDIS = 'session/redis';
4246
const CONFIG_PATH_SESSION_REDIS_HOST = 'session/redis/host';
@@ -57,6 +61,10 @@ class Session implements ConfigOptionsListInterface
5761
const CONFIG_PATH_SESSION_REDIS_DISABLE_LOCKING = 'session/redis/disable_locking';
5862
const CONFIG_PATH_SESSION_REDIS_MIN_LIFETIME = 'session/redis/min_lifetime';
5963
const CONFIG_PATH_SESSION_REDIS_MAX_LIFETIME = 'session/redis/max_lifetime';
64+
const CONFIG_PATH_SESSION_REDIS_SENTINEL_SERVERS = 'session/redis/sentinel_servers';
65+
const CONFIG_PATH_SESSION_REDIS_SENTINEL_MASTER = 'session/redis/sentinel_master';
66+
const CONFIG_PATH_SESSION_REDIS_SENTINEL_VERIFY_MASTER = 'session/redis/sentinel_verify_master';
67+
const CONFIG_PATH_SESSION_REDIS_SENTINEL_CONNECT_RETRIES = 'session/redis/sentinel_connect_retries';
6068

6169
/**
6270
* @var array
@@ -80,7 +88,9 @@ class Session implements ConfigOptionsListInterface
8088
self::INPUT_KEY_SESSION_REDIS_BOT_LIFETIME => '7200',
8189
self::INPUT_KEY_SESSION_REDIS_DISABLE_LOCKING => '0',
8290
self::INPUT_KEY_SESSION_REDIS_MIN_LIFETIME => '60',
83-
self::INPUT_KEY_SESSION_REDIS_MAX_LIFETIME => '2592000'
91+
self::INPUT_KEY_SESSION_REDIS_MAX_LIFETIME => '2592000',
92+
self::INPUT_KEY_SESSION_REDIS_SENTINEL_VERIFY_MASTER => '0',
93+
self::INPUT_KEY_SESSION_REDIS_SENTINEL_CONNECT_RETRIES => '5',
8494
];
8595

8696
/**
@@ -121,6 +131,11 @@ class Session implements ConfigOptionsListInterface
121131
self::INPUT_KEY_SESSION_REDIS_DISABLE_LOCKING => self::CONFIG_PATH_SESSION_REDIS_DISABLE_LOCKING,
122132
self::INPUT_KEY_SESSION_REDIS_MIN_LIFETIME => self::CONFIG_PATH_SESSION_REDIS_MIN_LIFETIME,
123133
self::INPUT_KEY_SESSION_REDIS_MAX_LIFETIME => self::CONFIG_PATH_SESSION_REDIS_MAX_LIFETIME,
134+
self::INPUT_KEY_SESSION_REDIS_SENTINEL_MASTER => self::CONFIG_PATH_SESSION_REDIS_SENTINEL_MASTER,
135+
self::INPUT_KEY_SESSION_REDIS_SENTINEL_SERVERS => self::CONFIG_PATH_SESSION_REDIS_SENTINEL_SERVERS,
136+
self::INPUT_KEY_SESSION_REDIS_SENTINEL_CONNECT_RETRIES =>
137+
self::CONFIG_PATH_SESSION_REDIS_SENTINEL_CONNECT_RETRIES,
138+
self::INPUT_KEY_SESSION_REDIS_SENTINEL_VERIFY_MASTER => self::CONFIG_PATH_SESSION_REDIS_SENTINEL_VERIFY_MASTER,
124139
];
125140

126141
/**
@@ -246,6 +261,30 @@ public function getOptions()
246261
self::CONFIG_PATH_SESSION_REDIS_MAX_LIFETIME,
247262
'Redis max session lifetime, in seconds'
248263
),
264+
new TextConfigOption(
265+
self::INPUT_KEY_SESSION_REDIS_SENTINEL_MASTER,
266+
TextConfigOption::FRONTEND_WIZARD_TEXT,
267+
self::CONFIG_PATH_SESSION_REDIS_SENTINEL_MASTER,
268+
'Redis Sentinel master'
269+
),
270+
new TextConfigOption(
271+
self::INPUT_KEY_SESSION_REDIS_SENTINEL_SERVERS,
272+
TextConfigOption::FRONTEND_WIZARD_TEXT,
273+
self::INPUT_KEY_SESSION_REDIS_SENTINEL_SERVERS,
274+
'Redis Sentinel servers, comma separated'
275+
),
276+
new TextConfigOption(
277+
self::INPUT_KEY_SESSION_REDIS_SENTINEL_VERIFY_MASTER,
278+
TextConfigOption::FRONTEND_WIZARD_TEXT,
279+
self::CONFIG_PATH_SESSION_REDIS_SENTINEL_VERIFY_MASTER,
280+
'Redis Sentinel verify master. Values: false (default), true'
281+
),
282+
new TextConfigOption(
283+
self::INPUT_KEY_SESSION_REDIS_SENTINEL_CONNECT_RETRIES,
284+
TextConfigOption::FRONTEND_WIZARD_TEXT,
285+
self::CONFIG_PATH_SESSION_REDIS_SENTINEL_CONNECT_RETRIES,
286+
'Redis Sentinel connect retries.'
287+
),
249288
];
250289
}
251290

setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/SessionTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function setUp()
3232
public function testGetOptions()
3333
{
3434
$options = $this->configList->getOptions();
35-
$this->assertCount(19, $options);
35+
$this->assertCount(23, $options);
3636

3737
$this->assertArrayHasKey(0, $options);
3838
$this->assertInstanceOf(SelectConfigOption::class, $options[0]);
@@ -156,7 +156,11 @@ public function testCreateConfigWithSessionSaveRedis()
156156
'bot_lifetime' => '',
157157
'disable_locking' => '',
158158
'min_lifetime' => '',
159-
'max_lifetime' => ''
159+
'max_lifetime' => '',
160+
'sentinel_master' => '',
161+
'sentinel_servers' => '',
162+
'sentinel_connect_retries' => '',
163+
'sentinel_verify_master' => '',
160164
]
161165

162166
]
@@ -209,7 +213,11 @@ public function testCreateConfigWithRedisInput()
209213
'bot_lifetime' => '',
210214
'disable_locking' => '',
211215
'min_lifetime' => '60',
212-
'max_lifetime' => '3600'
216+
'max_lifetime' => '3600',
217+
'sentinel_master' => '',
218+
'sentinel_servers' => '',
219+
'sentinel_connect_retries' => '',
220+
'sentinel_verify_master' => '',
213221
]
214222
],
215223

0 commit comments

Comments
 (0)