I need to get all active sessions' data from my Rails application. I am using Redis for session store.
I tried REDIS.keys
and then REDIS.get("SESSION_KEY")
but it seems like encrypted data.
Is there any painless solution to get live sessions' data on Rails?
Thanks.
Redis Enterprise is a popular database ideal for both cache and session store use cases, delivering both the high-availability required for caching and session store scenarios as well as the durability needed for session store with in-memory replication.
In Rails, session object is sent back and forth inside cookies. When you set session[:user_id] = 3 inside of your controller action, the response sent from that action will have a header Set-Cookie: my-session-cookie .
In Rails, data can be save and retrieve using session method. To store data in the session, assign it to the key. To remove data from the session, assign that key to be nil. To reset the entire session, use reset_session.
Ruby on Rails using Marshal method for saving objects to cache.
For example:
https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/rack_cache.rb#L17
You can unmarshalling this data as follows:
Marshal.load(REDIS.get("SESSION_KEY"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With