Needs More Blink Tag Rotating Header Image

How to migrate from MysqlSessionStore to MemCacheStore

At reQall we started out using the standard ActiveRecordStore for web session data, but switched along the way to MySQLSessionStore. Lately we’ve been trying to reduce DB load and decided to move our sessions into memcached (they’re soft state, after all). So, easy enough to do in Rails 2.x right? Switch your session container, restart your thins and you’re off to the races.

The catch is, we didn’t really want to force all our users to re-log into the app.  We could, and most probably wouldn’t notice, but that’s not how we roll.  So, we decided to migrate all the existing sessions from MySQL to Memcached.  Turns out it’s pretty easy.  MySQLSessionStore  keeps everything in a data column in the sessions table, which contains the base64-encoded output of Marshal.dump(<your session hash>).   The built-in logic in memcache-client handles the marshaling and unmarshaling when creating the new sessions, so migrating looks something like this on the console:

Simple, no? A word to the wise, though – do it in batches of 1000. Session.all would be bad.

Comments are closed.

SEO Powered by Platinum SEO from Techblissonline