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.

Redis cache store

Usage

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'
}

Software Engineer. Interested in Full-Stack Development and DevOps.

Software Engineer. Interested in Full-Stack Development and DevOps.