Redis Store to Store Session
I use Redis to store session and cache. And when I try to cache some session values, I get an exception “TypeError (can’t dump TCPSocket)”. I have researched this problem. It happened because session.slice(‘keys’) returns not simple Hash instance, but SessionHash. So instance method to_hash fixes all troubles. Example:
Rails.cache.write("key", session.except("flash", :session_id, :_csrf_token))
Solution:
Rails.cache.write("key", session.except("flash", :session_id, :_csrf_token).to_hash)