From 6638d5e0b9e3a8a2cd9a552be977b62edee49ac7 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 31 May 2015 13:20:45 +0200 Subject: [PATCH 1/3] Create RedisSessionHandler.php --- .../Storage/Handler/RedisSessionHandler.php | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php new file mode 100644 index 000000000000..b4a29047f47f --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php @@ -0,0 +1,89 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + + +namespace Symfony\Component\HttpFoundation\Session\Storage\Handler; + + +/** + * RedisSessionHandler + * + * @author Fabien Potencier + * @author stackoverflow + * + */ +class RedisSessionHandler implements \SessionHandlerInterface +{ + /** + * @var \Redis driver + */ + private $redis; + + /** + * @var int Time to live in seconds + */ + private $ttl; + + /** + * Class Constructor + * + * @param \Redis $redis A memcached instance + * @param int $ttl Session lifetime + */ + public function __construct(\Redis $redis, $ttl) + { + + $this->redis = $redis; + $this->ttl = $ttl; + } + + /** + * {@inheritDoc} + */ + public function open($savePath, $sessionName) + { + return true; + } + /** + * {@inheritDoc} + */ + public function read($sessionId) + { + return (string) $this->redis->get($sessionId); + } + /** + * {@inheritDoc} + */ + public function write($sessionId, $data) + { + return $this->redis->setex($sessionId, $this->ttl, $data); + } + /** + * {@inheritDoc} + */ + public function destroy($sessionId) + { + return 1 === $this->redis->delete($sessionId); + } + /** + * {@inheritDoc} + */ + public function gc($lifetime) + { + return true; + } + /** + * {@inheritDoc} + */ + public function close() + { + return true; + } +} From 150f88b7c09485600516f3dcbc8469cea273a632 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 31 May 2015 13:32:37 +0200 Subject: [PATCH 2/3] Update RedisSessionHandler.php --- .../Storage/Handler/RedisSessionHandler.php | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php index b4a29047f47f..47bfa6d05e30 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php @@ -1,4 +1,5 @@ redis = $redis; $this->ttl = $ttl; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function open($savePath, $sessionName) { return true; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function read($sessionId) { return (string) $this->redis->get($sessionId); } /** - * {@inheritDoc} + * {@inheritdoc} */ public function write($sessionId, $data) { return $this->redis->setex($sessionId, $this->ttl, $data); } /** - * {@inheritDoc} + * {@inheritdoc} */ public function destroy($sessionId) { return 1 === $this->redis->delete($sessionId); } /** - * {@inheritDoc} + * {@inheritdoc} */ public function gc($lifetime) { return true; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function close() { From 33aa1766552c9b37acbb59a40a417968d91a5818 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 31 May 2015 13:38:25 +0200 Subject: [PATCH 3/3] Update RedisSessionHandler.php | Q | A | ------------- | --- | Bug Fix? | no | New Feature? | yes | BC Breaks? | no | Deprecations? | no | Tests Pass? | yes | Fixed Tickets | | License | MIT | Doc PR | --- .../Session/Storage/Handler/RedisSessionHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php index 47bfa6d05e30..f764f6b92311 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php @@ -85,3 +85,4 @@ public function close() return true; } } +