Skip to content

Commit

Permalink
chore(redis): reduce connect timeout from 1s to 0.2s
Browse files Browse the repository at this point in the history
Prevent web workers from being stalled when Redis is down.
  • Loading branch information
colinux committed Jun 12, 2024
1 parent 069cb04 commit f504e79
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 11 additions & 7 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,21 @@

# Use a different cache store in production.
if ENV['REDIS_CACHE_URL'].present?
redis_options = { url: ENV['REDIS_CACHE_URL'] }
redis_options[:ssl] = (ENV['REDIS_CACHE_SSL'] == 'enabled')
redis_options = {
url: ENV['REDIS_CACHE_URL'],
connect_timeout: 0.2,
error_handler: -> (method:, returning:, exception:) {
Sentry.capture_exception exception, level: 'warning',
tags: { method: method, returning: returning }
}
}

redis_options[:ssl] = ENV['REDIS_CACHE_SSL'] == 'enabled'

if ENV['REDIS_CACHE_SSL_VERIFY_NONE'] == 'enabled'
redis_options[:ssl_params] = { verify_mode: OpenSSL::SSL::VERIFY_NONE }
end

redis_options[:error_handler] = -> (method:, returning:, exception:) {
Sentry.capture_exception exception, level: 'warning',
tags: { method: method, returning: returning }
}

config.cache_store = :redis_cache_store, redis_options
end

Expand Down
3 changes: 2 additions & 1 deletion config/initializers/kredis.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
redis_volatile_options = {
url: ENV['REDIS_CACHE_URL'], # will fallback to default redis url if empty, and won't fail if there is no redis server
ssl: ENV['REDIS_CACHE_SSL'] == 'enabled'
ssl: ENV['REDIS_CACHE_SSL'] == 'enabled',
connect_timeout: 0.2
}
redis_volatile_options[:ssl_params] = { verify_mode: OpenSSL::SSL::VERIFY_NONE } if ENV['REDIS_CACHE_SSL_VERIFY_NONE'] == 'enabled'

Expand Down

0 comments on commit f504e79

Please sign in to comment.