Configuration Cache and Rails Session Store with Redis

The main purpose of caching is making the application work faster. But also this mechanism can help to more flexibly manage data, a good example is session management.

Kirill Shevchenko
Jun 22, 2018 · 3 min read
Image for post
Image for post

Redis cache store


gem 'redis'
gem 'hiredis'
config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
config.action_controller.perform_caching = true

Session store

config.session_store :cache_store, key: ENV['APP_SESSION_KEY']

Solution For Rails < 5.2

gem 'redis-rails'
config.cache_store = :redis_store, ENV['REDIS_URL']
config.session_store :redis_store, {
servers: [
{ host: ENV['REDIS_HOST'], port: 6379, db: 0 },
key: '_some_session_key'
Image for post
Image for post
Image for post
Image for post

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store