Using redis for session store in a Hanami application
To be able to list logged in users in my Hanami application I’ve switched from cookies to redis for session store. The setup is quite brief thanks to the redis-rack gem.
1. Gemfile
Add the gem to the Gemfile:
2. application.rb
Require redis:
Switch from cookies to redis:
3. Admin panel controller action
In my simple example below the code returns an array of logged-in user IDs to then query from the DB.
The s_key
returns the rack session ID and the s_value
returns the everything stored in the session:
Credits
Thanks to Luca Guidi, the creator of the Hanami framework and the redis-store.