Skip to content

Commit

Permalink
feat(redis): add session store config
Browse files Browse the repository at this point in the history
  • Loading branch information
gmq committed May 22, 2023
1 parent f68a6d2 commit fe5159d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/potassium/assets/config/initializers/session_store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://github.com/redis-store/redis-store/issues/358#issuecomment-1537920008
class RedisClient::Config
alias original_initialize initialize

def initialize(**kwargs)
# remove not supported kwargs
original_initialize(
**kwargs.except(:raw, :serializer, :marshalling, :namespace, :scheme)
)
end
end

Rails.application.config.session_store :redis_store, {
servers: [{
url: ENV['REDIS_URL']
}],
expire_after: 3.days,
key: '_app_session',
secure: Rails.env.production?
}
6 changes: 6 additions & 0 deletions lib/potassium/recipes/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ def create
add_redis
add_docker_compose_redis_config
set_redis_dot_env
add_session_store_config
end

def install
Expand Down Expand Up @@ -49,4 +50,9 @@ def set_redis_dot_env
TEXT
)
end

def add_session_store_config
copy_file("../assets/config/initializers/session_store.rb",
"config/initializers/session_store.rb", force: true)
end
end
5 changes: 5 additions & 0 deletions spec/features/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@

expect(compose_content[:services]).to include(:redis)
end

it 'copies session store config' do
content = IO.read("#{project_path}/config/initializers/session_store.rb")
expect(content).to include("RedisClient::Config")
end
end
end

0 comments on commit fe5159d

Please sign in to comment.