Commit 88671590 authored by wehr's avatar wehr Committed by Eloy Lafuente
Browse files

MDL-57655 session: Adds igbinary serializer to Redis session handler

parent ae8e8e6a
...@@ -261,6 +261,9 @@ $CFG->admin = 'admin'; ...@@ -261,6 +261,9 @@ $CFG->admin = 'admin';
// $CFG->session_redis_prefix = ''; // Optional, default is don't set one. // $CFG->session_redis_prefix = ''; // Optional, default is don't set one.
// $CFG->session_redis_acquire_lock_timeout = 120; // $CFG->session_redis_acquire_lock_timeout = 120;
// $CFG->session_redis_lock_expire = 7200; // $CFG->session_redis_lock_expire = 7200;
// Use the igbinary serializer instead of the php default one. Note that phpredis must be compiled with
// igbinary support to make the setting to work. Also, if you change the serializer you have to flush the database!
// $CFG->session_redis_serializer_use_igbinary = false; // Optional, default is PHP builtin serializer.
// //
// Memcache session handler (requires memcached server and memcache extension): // Memcache session handler (requires memcached server and memcache extension):
// $CFG->session_handler_class = '\core\session\memcache'; // $CFG->session_handler_class = '\core\session\memcache';
......
...@@ -50,6 +50,8 @@ class redis extends handler { ...@@ -50,6 +50,8 @@ class redis extends handler {
protected $prefix = ''; protected $prefix = '';
/** @var int $acquiretimeout how long to wait for session lock in seconds */ /** @var int $acquiretimeout how long to wait for session lock in seconds */
protected $acquiretimeout = 120; protected $acquiretimeout = 120;
/** @var int $serializer The serializer to use */
protected $serializer = \Redis::SERIALIZER_PHP;
/** /**
* @var int $lockexpire how long to wait in seconds before expiring the lock automatically * @var int $lockexpire how long to wait in seconds before expiring the lock automatically
* so that other requests may continue execution, ignored if PECL redis is below version 2.2.0. * so that other requests may continue execution, ignored if PECL redis is below version 2.2.0.
...@@ -91,6 +93,10 @@ class redis extends handler { ...@@ -91,6 +93,10 @@ class redis extends handler {
$this->acquiretimeout = (int)$CFG->session_redis_acquire_lock_timeout; $this->acquiretimeout = (int)$CFG->session_redis_acquire_lock_timeout;
} }
if (!empty($CFG->session_redis_serializer_use_igbinary) && defined('\Redis::SERIALIZER_IGBINARY')) {
$this->serializer = \Redis::SERIALIZER_IGBINARY; // Set igbinary serializer if phpredis supports it.
}
// The following configures the session lifetime in redis to allow some // The following configures the session lifetime in redis to allow some
// wriggle room in the user noticing they've been booted off and // wriggle room in the user noticing they've been booted off and
// letting them log back in before they lose their session entirely. // letting them log back in before they lose their session entirely.
...@@ -150,7 +156,7 @@ class redis extends handler { ...@@ -150,7 +156,7 @@ class redis extends handler {
if (!$this->connection->connect($this->host, $this->port, 1)) { if (!$this->connection->connect($this->host, $this->port, 1)) {
throw new RedisException('Unable to connect to host.'); throw new RedisException('Unable to connect to host.');
} }
if (!$this->connection->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP)) { if (!$this->connection->setOption(\Redis::OPT_SERIALIZER, $this->serializer)) {
throw new RedisException('Unable to set Redis PHP Serializer option.'); throw new RedisException('Unable to set Redis PHP Serializer option.');
} }
...@@ -389,4 +395,4 @@ class redis extends handler { ...@@ -389,4 +395,4 @@ class redis extends handler {
$this->handler_destroy($sid); $this->handler_destroy($sid);
} }
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment