I have written a module called Redis Sessions. It is dependent on the Redis module to connect to a Redis instance, and use that for session management using the Redis module's API. It's intended to be a drop-in replacement for Drupal core's sessions in the database, with all the normal Drupal performance enhancements (like no session writes for anonymous users and the session_migrate method).

I'd like to share this module and potentially get it added to the Redis project as a submodule. I'll add a patch for this.

#2 2876099_1_redis_sessions.patch14.37 KBtobby
Members fund testing for the Drupal project. Drupal Association Learn more


tobby created an issue. See original summary.

tobby’s picture

Pryrios’s picture

I am deeply interested in this and was going to implement something similar myself. I will gladly try it to see how it works and help on completing it. It looks promising, and you may very well saved me a lot of time...

tobby’s picture

Pryrios, glad to hear that. Certainly let me know how it fits your use case. I'd be interested in knowing how close to a drop-in replacement this module is for others.

FWIW, while discussing the approach I took on this module, I think a potential future step would be to abstract out the Redis portion and make this backend-agnostic, so that it could use anything else that has a PHP session handler (probably through the use of a basic plugin manager, to point the read/write functionality to the appropriate API).

Pryrios’s picture

So something on the lines of what https://www.drupal.org/project/session_proxy did on D7?

I was thinking about something similar, although I'm still figuring out how SessionManager and SessionHandler works (I'm not sure what is SessionHandler being used for).

I'm configuring redis/redis_sessions right now, so I will be able to tell you something later today.

Pryrios’s picture

Update: It is working good as far as I have tested for basic functionality (login/logout, maintaing session for awhile, storing values in $_SESSION, etc...).

I will develop some tests in the coming days, including stress tests, as I progress on my project to see if I detect some strange behavior.

Good work!

Perignon’s picture

I could use this on Drupal7. I am migrating from MongoDB to Redis. I will see if I have time to backport this.