File tree Expand file tree Collapse file tree 8 files changed +157
-0
lines changed Expand file tree Collapse file tree 8 files changed +157
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Used in creating options for Redis Fallback Handler config value selection
4
+ */
5
+ namespace Kodbruket \RedisFallback \Model \System \Config ;
6
+
7
+ use Magento \Framework \Option \ArrayInterface ;
8
+
9
+ /**
10
+ * Class RedisHandler
11
+ */
12
+ class RedisHandler implements ArrayInterface
13
+ {
14
+ const FILES = 'files ' ;
15
+ const DATABASE = 'db ' ;
16
+
17
+ /**
18
+ * Options getter
19
+ *
20
+ * @return array
21
+ */
22
+ public function toOptionArray ()
23
+ {
24
+ return [
25
+ [
26
+ 'value ' => self ::FILES ,
27
+ 'label ' => __ ('Files ' )
28
+ ],
29
+ [
30
+ 'value ' => self ::DATABASE ,
31
+ 'label ' => __ ('Database ' )
32
+ ]
33
+ ];
34
+ }
35
+
36
+ /**
37
+ * Get options in "key-value" format
38
+ *
39
+ * @return array
40
+ */
41
+ public function toArray ()
42
+ {
43
+ return [
44
+ self ::FILES => __ ('Files ' ),
45
+ self ::DATABASE => __ ('Database ' )
46
+ ];
47
+ }
48
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Kodbruket \RedisFallback \Session ;
4
+
5
+ use Magento \Framework \Session \SaveHandlerFactory ;
6
+ use Magento \Framework \Session \Config \ConfigInterface ;
7
+ use Magento \Framework \Exception \SessionException ;
8
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
9
+ use Magento \Store \Model \ScopeInterface ;
10
+
11
+ class SaveHandler extends \Magento \Framework \Session \SaveHandler
12
+ {
13
+ const REDIS_FALLBACK_HANDLER_CONFIG_XML = 'system/redis_fallback/handler ' ;
14
+
15
+ /**
16
+ * Constructor
17
+ *
18
+ * @param SaveHandlerFactory $saveHandlerFactory
19
+ * @param ConfigInterface $sessionConfig
20
+ * @param string $default
21
+ * @param ScopeConfigInterface $scopeConfig
22
+ */
23
+ public function __construct (
24
+ SaveHandlerFactory $ saveHandlerFactory ,
25
+ ConfigInterface $ sessionConfig ,
26
+ $ default = self ::DEFAULT_HANDLER ,
27
+ ScopeConfigInterface $ scopeConfig
28
+ ) {
29
+ $ fallbackHandler = $ scopeConfig ->getValue (self ::REDIS_FALLBACK_HANDLER_CONFIG_XML , ScopeInterface::SCOPE_STORE );
30
+ if ($ fallbackHandler ){
31
+ $ default = $ fallbackHandler ;
32
+ }
33
+
34
+ parent ::__construct ( $ saveHandlerFactory , $ sessionConfig , $ default );
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " kodbruket/module-redisfallback" ,
3
+ "description" : " Fallback Redis session to Db on failure" ,
4
+ "type" : " magento2-module" ,
5
+ "license" : [
6
+ " proprietary"
7
+ ],
8
+ "authors" :[
9
+ {
10
+ "name" :" Jimmy" ,
11
+ "email" :" phu@kodbruket.se"
12
+ }
13
+ ],
14
+ "require" : {
15
+ },
16
+ "autoload" : {
17
+ "files" : [
18
+ " registration.php"
19
+ ],
20
+ "psr-4" : {
21
+ "Kodbruket\\ RedisFallback\\ " : " "
22
+ }
23
+ }
24
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+ <!--
3
+ /**
4
+ * Copyright © Magento, Inc. All rights reserved.
5
+ * See COPYING.txt for license details.
6
+ */
7
+ -->
8
+ <config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:module:Magento_Config:etc/system_file.xsd" >
9
+ <system >
10
+ <section id =" system" >
11
+ <group id =" redis_fallback" translate =" label" showInDefault =" 1" showInWebsite =" 0" showInStore =" 0" sortOrder =" 800" >
12
+ <label >Redis Fallback</label >
13
+ <field id =" handler" translate =" label" type =" select" sortOrder =" 0" showInDefault =" 1" showInWebsite =" 0" showInStore =" 0" canRestore =" 1" >
14
+ <label >Fallback Handler</label >
15
+ <source_model >Kodbruket\RedisFallback\Model\System\Config\RedisHandler</source_model >
16
+ </field >
17
+ </group >
18
+ </section >
19
+ </system >
20
+ </config >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+ <config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:Store/etc/config.xsd" >
3
+ <default >
4
+ <system >
5
+ <redis_fallback >
6
+ <handler >db</handler >
7
+ </redis_fallback >
8
+ </system >
9
+ </default >
10
+ </config >
Original file line number Diff line number Diff line change
1
+ <config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:ObjectManager/etc/config.xsd" >
2
+ <preference for =" Magento\Framework\Session\SaveHandler" type =" Kodbruket\RedisFallback\Session\SaveHandler" />
3
+ </config >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+ <config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:Module/etc/module.xsd" >
3
+ <module name =" Kodbruket_RedisFallback" setup_version =" 1.0.0" >
4
+ <sequence >
5
+ </sequence >
6
+ </module >
7
+ </config >
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use \Magento \Framework \Component \ComponentRegistrar ;
4
+
5
+ ComponentRegistrar::register (
6
+ ComponentRegistrar::MODULE ,
7
+ 'Kodbruket_RedisFallback ' ,
8
+ __DIR__
9
+ );
You can’t perform that action at this time.
0 commit comments