Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8382757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:00:03+00:00 2026-06-09T17:00:03+00:00

I have a large application that as many, many thousand active sessions. I want

  • 0

I have a large application that as many, many thousand active sessions. I want to migrate into a Redis session store using this. And ideally, I want my current sessions to stay active.

Does anyone have any experience in migrating active sessions. I assume I write either a migration or a rake task (I think migration, so I can drop the old table as part of this), and I want to just write into redis all the current details.

old_sessions = ActiveRecord::Base.connection.select_all("select * from sessions")
old_sessions.each { |session| $redis.set(????? ????) }

But I am worried about data integrity.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:00:05+00:00Added an answer on June 9, 2026 at 5:00 pm

    Alright, after a day of hacking this up, here’s what I came up with:

    class MoveActiveRecordSesionsIntoRedis < ActiveRecord::Migration
      def up
        #get all the sessions from the last month
        old_sessions = ActiveRecord::Base.connection.select_all("select * from sessions where updated_at > '#{Time.now - 1.month}'")
    
        old_sessions.each do |session|
    
    
          #convert the base64 data back into the object
          data = ActiveRecord::SessionStore::Session.unmarshal(session["data"])
    
          #load each session into Redis, dumping the object appropriately      
          $redis.setex session["session_id"], 
                       1.month.to_i, 
                       Marshal.dump(data).to_s.force_encoding(Encoding::BINARY)
        end
    
        #drop the old session table (So long unecessary 3Gigs!)
        drop_table :sessions
      end
    
      def down
        raise ActiveRecord::IrreversibleMigration, "Session face-plant!"
      end
    end
    

    I’m putting this here as a reference. Or if you see something wrong with it, I’m all ears.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large acceptance test suite that runs the source application many thousands
I have a considerably large application that uses MSDTC. How many ports should I
We have an ASP classic ERP (very large application) that we want to rewrite
I have a rather large application that has literally a hundred DDLs with Yes
I have a fairly large application that uses WPF for its user interface. I
I have this relatively large numerical application code that may run for a few
I have a very large set of permissions in my application that I represent
I have an application that outputs large amounts of text data to an MFC
I have an application that is pretty memory hungry. It holds a large amount
I have a Java application that makes heavy use of a large file, to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.