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

Update colinmollenhour/php-redis-session-abstract #39

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"colinmollenhour/cache-backend-file": "1.4",
"colinmollenhour/cache-backend-redis": "1.10.2",
"colinmollenhour/credis": "1.6",
"colinmollenhour/php-redis-session-abstract": "~1.2.2",
"colinmollenhour/php-redis-session-abstract": "~1.3.8",
"composer/composer": "1.4.1",
"magento/composer": "~1.2.0",
"magento/magento-composer-installer": ">=0.1.11",
Expand All @@ -50,6 +50,7 @@
"symfony/process": "~2.1",
"tedivm/jshrink": "~1.1.0",
"tubalmartin/cssmin": "4.1.0",
"webonyx/graphql-php": "^0.11.1",
"zendframework/zend-captcha": "^2.7.1",
"zendframework/zend-code": "^3.1.0",
"zendframework/zend-config": "^2.6.0",
Expand All @@ -75,8 +76,7 @@
"zendframework/zend-text": "^2.6.0",
"zendframework/zend-uri": "^2.5.1",
"zendframework/zend-validator": "^2.6.0",
"zendframework/zend-view": "^2.8.1",
"webonyx/graphql-php": "^0.11.1"
"zendframework/zend-view": "^2.8.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.1.1",
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ class Config implements \Cm\RedisSession\Handler\ConfigInterface
*/
const PARAM_BREAK_AFTER = 'session/redis/break_after';

/**
* Configuration path for comma separated list of sentinel servers
*/
const PARAM_SENTINEL_SERVERS = 'session/redis/sentinel_servers';

/**
* Configuration path for sentinel master
*/
const PARAM_SENTINEL_MASTER = 'session/redis/sentinel_master';

/**
* Configuration path for verify sentinel master flag
*/
const PARAM_SENTINEL_VERIFY_MASTER = 'session/redis/sentinel_verify_master';

/**
* Configuration path for number of sentinel connection retries
*/
const PARAM_SENTINEL_CONNECT_RETRIES = 'session/redis/sentinel_connect_retries';

/**
* Cookie lifetime config path
*/
Expand All @@ -115,6 +135,11 @@ class Config implements \Cm\RedisSession\Handler\ConfigInterface
*/
const SESSION_MAX_LIFETIME = 31536000;

/**
* Try to break lock for at most this many seconds
*/
const DEFAULT_FAIL_AFTER = 15;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this one not configurable? Comparing to PARAM_BREAK_AFTER?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also necessary to update setup:config:set with new params (in \Magento\Setup\Model\ConfigOptionsList\Session).

Could you please also update http://devdocs.magento.com/guides/v2.2/config-guide/redis/redis-session.html ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied DEFAULT_FAIL_AFTER from 2.2-develop https://github.com/magento/magento2/blob/0839bd421bd5812e9aa7c943b89ecae9d5008832/lib/internal/Magento/Framework/Session/SaveHandler/Redis/Config.php#L121 Should I change it to be configurable here?

Thanks for pointing out the changes required to setup:config:set. I'll get that taken care of.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it... ok, let's leave it as is.


/**
* Deployment config
*
Expand Down Expand Up @@ -293,4 +318,44 @@ public function getLifetime()
}
return (int)$this->scopeConfig->getValue(self::XML_PATH_COOKIE_LIFETIME, StoreScopeInterface::SCOPE_STORE);
}

/**
* {@inheritdoc}
*/
public function getSentinelServers()
{
return $this->deploymentConfig->get(self::PARAM_SENTINEL_SERVERS);
}

/**
* {@inheritdoc}
*/
public function getSentinelMaster()
{
return $this->deploymentConfig->get(self::PARAM_SENTINEL_MASTER);
}

/**
* {@inheritdoc}
*/
public function getSentinelVerifyMaster()
{
return $this->deploymentConfig->get(self::PARAM_SENTINEL_VERIFY_MASTER);
}

/**
* {@inheritdoc}
*/
public function getSentinelConnectRetries()
{
return $this->deploymentConfig->get(self::PARAM_SENTINEL_CONNECT_RETRIES);
}

/**
* {@inheritdoc}
*/
public function getFailAfter()
{
return self::DEFAULT_FAIL_AFTER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,49 @@ public function testGetLifetimeFrontend()
->willReturn($expectedLifetime);
$this->assertEquals($this->config->getLifetime(), $expectedLifetime);
}

public function testGetSentinelServers()
{
$expected = 'server-1,server-2';
$this->deploymentConfigMock->expects($this->once())
->method('get')
->with(Config::PARAM_SENTINEL_SERVERS)
->willReturn($expected);
$this->assertEquals($expected, $this->config->getSentinelServers());
}

public function testGetSentinelMaster()
{
$expected = 'master';
$this->deploymentConfigMock->expects($this->once())
->method('get')
->with(Config::PARAM_SENTINEL_MASTER)
->willReturn($expected);
$this->assertEquals($this->config->getSentinelMaster(), $expected);
}

public function testGetSentinelVerifyMaster()
{
$expected = '1';
$this->deploymentConfigMock->expects($this->once())
->method('get')
->with(Config::PARAM_SENTINEL_VERIFY_MASTER)
->willReturn($expected);
$this->assertEquals($this->config->getSentinelVerifyMaster(), $expected);
}

public function testGetSentinelConnectRetries()
{
$expected = '10';
$this->deploymentConfigMock->expects($this->once())
->method('get')
->willReturn(Config::PARAM_SENTINEL_CONNECT_RETRIES)
->willReturn($expected);
$this->assertEquals($this->config->getSentinelConnectRetries(), $expected);
}

public function testGetFailAfter()
{
$this->assertEquals($this->config->getFailAfter(), Config::DEFAULT_FAIL_AFTER);
}
}
41 changes: 40 additions & 1 deletion setup/src/Magento/Setup/Model/ConfigOptionsList/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class Session implements ConfigOptionsListInterface
const INPUT_KEY_SESSION_REDIS_DISABLE_LOCKING = 'session-save-redis-disable-locking';
const INPUT_KEY_SESSION_REDIS_MIN_LIFETIME = 'session-save-redis-min-lifetime';
const INPUT_KEY_SESSION_REDIS_MAX_LIFETIME = 'session-save-redis-max-lifetime';
const INPUT_KEY_SESSION_REDIS_SENTINEL_SERVERS = 'session-save-redis-sentinel-servers';
const INPUT_KEY_SESSION_REDIS_SENTINEL_MASTER = 'session-save-redis-sentinel-master';
const INPUT_KEY_SESSION_REDIS_SENTINEL_VERIFY_MASTER = 'session-save-redis-sentinel-verify-master';
const INPUT_KEY_SESSION_REDIS_SENTINEL_CONNECT_RETRIES = 'session-save-redis-sentinel-connect-retires';

const CONFIG_PATH_SESSION_REDIS = 'session/redis';
const CONFIG_PATH_SESSION_REDIS_HOST = 'session/redis/host';
Expand All @@ -57,6 +61,10 @@ class Session implements ConfigOptionsListInterface
const CONFIG_PATH_SESSION_REDIS_DISABLE_LOCKING = 'session/redis/disable_locking';
const CONFIG_PATH_SESSION_REDIS_MIN_LIFETIME = 'session/redis/min_lifetime';
const CONFIG_PATH_SESSION_REDIS_MAX_LIFETIME = 'session/redis/max_lifetime';
const CONFIG_PATH_SESSION_REDIS_SENTINEL_SERVERS = 'session/redis/sentinel_servers';
const CONFIG_PATH_SESSION_REDIS_SENTINEL_MASTER = 'session/redis/sentinel_master';
const CONFIG_PATH_SESSION_REDIS_SENTINEL_VERIFY_MASTER = 'session/redis/sentinel_verify_master';
const CONFIG_PATH_SESSION_REDIS_SENTINEL_CONNECT_RETRIES = 'session/redis/sentinel_connect_retries';

/**
* @var array
Expand All @@ -80,7 +88,9 @@ class Session implements ConfigOptionsListInterface
self::INPUT_KEY_SESSION_REDIS_BOT_LIFETIME => '7200',
self::INPUT_KEY_SESSION_REDIS_DISABLE_LOCKING => '0',
self::INPUT_KEY_SESSION_REDIS_MIN_LIFETIME => '60',
self::INPUT_KEY_SESSION_REDIS_MAX_LIFETIME => '2592000'
self::INPUT_KEY_SESSION_REDIS_MAX_LIFETIME => '2592000',
self::INPUT_KEY_SESSION_REDIS_SENTINEL_VERIFY_MASTER => '0',
self::INPUT_KEY_SESSION_REDIS_SENTINEL_CONNECT_RETRIES => '5',
];

/**
Expand Down Expand Up @@ -121,6 +131,11 @@ class Session implements ConfigOptionsListInterface
self::INPUT_KEY_SESSION_REDIS_DISABLE_LOCKING => self::CONFIG_PATH_SESSION_REDIS_DISABLE_LOCKING,
self::INPUT_KEY_SESSION_REDIS_MIN_LIFETIME => self::CONFIG_PATH_SESSION_REDIS_MIN_LIFETIME,
self::INPUT_KEY_SESSION_REDIS_MAX_LIFETIME => self::CONFIG_PATH_SESSION_REDIS_MAX_LIFETIME,
self::INPUT_KEY_SESSION_REDIS_SENTINEL_MASTER => self::CONFIG_PATH_SESSION_REDIS_SENTINEL_MASTER,
self::INPUT_KEY_SESSION_REDIS_SENTINEL_SERVERS => self::CONFIG_PATH_SESSION_REDIS_SENTINEL_SERVERS,
self::INPUT_KEY_SESSION_REDIS_SENTINEL_CONNECT_RETRIES =>
self::CONFIG_PATH_SESSION_REDIS_SENTINEL_CONNECT_RETRIES,
self::INPUT_KEY_SESSION_REDIS_SENTINEL_VERIFY_MASTER => self::CONFIG_PATH_SESSION_REDIS_SENTINEL_VERIFY_MASTER,
];

/**
Expand Down Expand Up @@ -246,6 +261,30 @@ public function getOptions()
self::CONFIG_PATH_SESSION_REDIS_MAX_LIFETIME,
'Redis max session lifetime, in seconds'
),
new TextConfigOption(
self::INPUT_KEY_SESSION_REDIS_SENTINEL_MASTER,
TextConfigOption::FRONTEND_WIZARD_TEXT,
self::CONFIG_PATH_SESSION_REDIS_SENTINEL_MASTER,
'Redis Sentinel master'
),
new TextConfigOption(
self::INPUT_KEY_SESSION_REDIS_SENTINEL_SERVERS,
TextConfigOption::FRONTEND_WIZARD_TEXT,
self::INPUT_KEY_SESSION_REDIS_SENTINEL_SERVERS,
'Redis Sentinel servers, comma separated'
),
new TextConfigOption(
self::INPUT_KEY_SESSION_REDIS_SENTINEL_VERIFY_MASTER,
TextConfigOption::FRONTEND_WIZARD_TEXT,
self::CONFIG_PATH_SESSION_REDIS_SENTINEL_VERIFY_MASTER,
'Redis Sentinel verify master. Values: false (default), true'
),
new TextConfigOption(
self::INPUT_KEY_SESSION_REDIS_SENTINEL_CONNECT_RETRIES,
TextConfigOption::FRONTEND_WIZARD_TEXT,
self::CONFIG_PATH_SESSION_REDIS_SENTINEL_CONNECT_RETRIES,
'Redis Sentinel connect retries.'
),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function setUp()
public function testGetOptions()
{
$options = $this->configList->getOptions();
$this->assertCount(19, $options);
$this->assertCount(23, $options);

$this->assertArrayHasKey(0, $options);
$this->assertInstanceOf(SelectConfigOption::class, $options[0]);
Expand Down Expand Up @@ -156,7 +156,11 @@ public function testCreateConfigWithSessionSaveRedis()
'bot_lifetime' => '',
'disable_locking' => '',
'min_lifetime' => '',
'max_lifetime' => ''
'max_lifetime' => '',
'sentinel_master' => '',
'sentinel_servers' => '',
'sentinel_connect_retries' => '',
'sentinel_verify_master' => '',
]

]
Expand Down Expand Up @@ -209,7 +213,11 @@ public function testCreateConfigWithRedisInput()
'bot_lifetime' => '',
'disable_locking' => '',
'min_lifetime' => '60',
'max_lifetime' => '3600'
'max_lifetime' => '3600',
'sentinel_master' => '',
'sentinel_servers' => '',
'sentinel_connect_retries' => '',
'sentinel_verify_master' => '',
]
],

Expand Down