Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 665f593

Browse filesBrowse files
committed
NativeRedisSessionStorage added
- fix and simple unit test added
1 parent 99406eb commit 665f593
Copy full SHA for 665f593

File tree

Expand file treeCollapse file tree

2 files changed

+81
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+81
-0
lines changed
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\Session\Storage;
13+
14+
/**
15+
* NativeRedisSessionStorage.
16+
*
17+
* Driver for the redis session save hadlers provided by the redis PHP extension.
18+
*
19+
* @see https://github.com/nicolasff/phpredis
20+
*
21+
* @author Andrej Hudec <pulzarraider@gmail.com>
22+
*/
23+
class NativeRedisSessionStorage extends AbstractSessionStorage
24+
{
25+
/**
26+
* @var string
27+
*/
28+
private $savePath;
29+
30+
/**
31+
* Constructor.
32+
*
33+
* @param string $savePath Path of redis server.
34+
* @param array $options Session configuration options.
35+
*
36+
* @see AbstractSessionStorage::__construct()
37+
*/
38+
public function __construct($savePath = 'tcp://127.0.0.1:6379?persistent=0', array $options = array())
39+
{
40+
if (!extension_loaded('redis')) {
41+
throw new \RuntimeException('PHP does not have "redis" session module registered');
42+
}
43+
44+
$this->savePath = $savePath;
45+
parent::__construct($options);
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
protected function registerSaveHandlers()
52+
{
53+
ini_set('session.save_handler', 'redis');
54+
ini_set('session.save_path', $this->savePath);
55+
}
56+
}
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Symfony\Tests\Component\HttpFoundation\Session\Storage;
4+
5+
use Symfony\Component\HttpFoundation\Session\Storage\NativeRedisSessionStorage;
6+
7+
/**
8+
* Test class for NativeRedisSessionStorage.
9+
*
10+
* @runTestsInSeparateProcesses
11+
*/
12+
class NativeRedisSessionStorageTest extends \PHPUnit_Framework_TestCase
13+
{
14+
public function testSaveHandlers()
15+
{
16+
if (!extension_loaded('redis')) {
17+
$this->markTestSkipped('Skipped tests - Redis extension is not present');
18+
}
19+
20+
$storage = new NativeRedisSessionStorage('tcp://127.0.0.1:6379?persistent=0', array('name' => 'TESTING'));
21+
$this->assertEquals('redis', ini_get('session.save_handler'));
22+
$this->assertEquals('tcp://127.0.0.1:6379?persistent=0', ini_get('session.save_path'));
23+
$this->assertEquals('TESTING', ini_get('session.name'));
24+
}
25+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.