Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails: How can I get all sessions data from Redis on server side?

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.

like image 667
Salih Özdemir Avatar asked Dec 07 '15 13:12

Salih Özdemir


People also ask

Is Redis good for session store?

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.

Where does Rails store session data?

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 .

How do I use session storage in Rails?

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.


1 Answers

Decrypt the Rails session data from Redis

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"))
like image 82
Emre Can Yılmaz Avatar answered Sep 21 '22 14:09

Emre Can Yılmaz