8000 [HttpFoundation] Implement RedisSession Handler by gholol · Pull Request #14803 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] Implement RedisSession Handler #14803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <fabien@symfony.com>
* @author stackoverflow <admin@2.pl>
*
*/
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;
}
}

0