- Merge request !9Issue #2876099: Create submodule to store PHP sessions in Redis → (Open) created by Grimreaper
- 🇦🇺Australia darvanen Sydney, Australia
Forced rebase against dev branch. Here's a patch if anyone needs it.
- 🇦🇺Australia darvanen Sydney, Australia
Added a commit to make the submodule compatible with Drupal 10
- Status changed to Needs work
over 1 year ago 7:14am 6 November 2023 - 🇦🇺Australia darvanen Sydney, Australia
Ah ok, it wasn't that simple then, I'll do a more thorough job, thanks for pointing it out :)
You can easily override the Drupal session factory via *services.yml to the Redis session factory (a component that Symfony provides).
services: redis.client: class: Redis # Your Redis client class. factory: [ '@redis.factory', 'getClient' ] session_handler.storage: class: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler arguments: [ '@redis.client', { prefix: 'drupal_session:' } ]
I'm not sure if there are any downsides to this approach. If not, then mentioning this feature in the README would be helpful.
@hmdnawaz I use phpredis, so it's
class: Redis
, which is the global class provided by that PHP extension.- 🇵🇰Pakistan hmdnawaz
In case of Drupal redis module, can we use?
services: redis.client: class: Drupal\redis\Client\PhpRedis # Your Redis client class. factory: [ '@redis.factory', 'getClient' ] session_handler.storage: class: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler arguments: [ '@redis.client', { prefix: 'drupal_session:' } ]
- First commit to issue fork.
- 🇵🇰Pakistan hmdnawaz
There is an issue when using the RedisSessionHandler. When you clear the cache from the UI or use Drush, the logged-in user gets logged out.
- 🇮🇳India Shiv_Sharma
#52: works for me ;)
just adding stepsin your custom module add
services: redis.client: class: Drupal\redis\Client\PhpRedis factory: [ '@redis.factory', 'getClient' ] session_handler.storage: class: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler arguments: [ '@redis.client', { prefix: 'drupal_session:' } ]
and in settings.php add :
$settings['session_handler_class'] = 'Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler';
hope this help to others :)
- 🇦🇺Australia darvanen Sydney, Australia
I propose we adjust this issue to fully document that approach in the module code and docs.
- 🇺🇸United States devkinetic
I'm not sure what exactly is the "correct" way to do this... on a recent project we simply did
$settings['session_storage']['class'] = 'Drupal\redis\Cache\PhpRedis';
and it seemed to work pretty well! if anyone can provide a comparison or justification on the best approach, I would much appreciate it.In general, for our project, which consists of mostly logged in users, we saw a ~600% increase in throughput under load between that setting and also adding
$settings['session_write_lock'] = FALSE;
. Managing sessions through Redis appears to be a boon for performance and it would be great if this got rolled into the "default" config and setup.YMMV of course, as there are so many factors to consider.