From b5771bccc6031c3adbdee31064f1c0c981ab73d4 Mon Sep 17 00:00:00 2001
From: Stan Hu <stanhu@gmail.com>
Date: Fri, 19 Jul 2019 13:58:44 -0700
Subject: [PATCH] Use Rails 5.2 Redis caching store

This is the first step in providing a fault-tolerant and distributed
Redis caching store. We disable compression to avoid introducing a
change that could have an adverse effect in production.

Note that we won't be able to take advantage of the fault-tolerance and
distributed features yet until we solve
https://gitlab.com/gitlab-org/gitlab-ce/issues/64829.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/64794
---
 Gemfile                                              | 8 ++++----
 Gemfile.lock                                         | 8 ++++----
 changelogs/unreleased/sh-use-redis-caching-store.yml | 5 +++++
 config/application.rb                                | 5 ++++-
 4 files changed, 17 insertions(+), 9 deletions(-)
 create mode 100644 changelogs/unreleased/sh-use-redis-caching-store.yml

diff --git a/Gemfile b/Gemfile
index 61a6432a953..4cd75963e86 100644
--- a/Gemfile
+++ b/Gemfile
@@ -200,13 +200,13 @@ gem 'js_regex', '~> 3.1'
 # User agent parsing
 gem 'device_detector'
 
-# Cache
-gem 'redis-rails', '~> 5.0.2'
-
 # Redis
-gem 'redis', '~> 3.2'
+gem 'redis', '~> 4.0'
 gem 'connection_pool', '~> 2.0'
 
+# Redis session store
+gem 'redis-rails', '~> 5.0.2'
+
 # Discord integration
 gem 'discordrb-webhooks-blackst0ne', '~> 3.3', require: false
 
diff --git a/Gemfile.lock b/Gemfile.lock
index f89654c82fd..769af1fa20e 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -741,17 +741,17 @@ GEM
     recaptcha (4.13.1)
       json
     recursive-open-struct (1.1.0)
-    redis (3.3.5)
+    redis (4.1.2)
     redis-actionpack (5.0.2)
       actionpack (>= 4.0, < 6)
       redis-rack (>= 1, < 3)
       redis-store (>= 1.1.0, < 2)
-    redis-activesupport (5.0.4)
+    redis-activesupport (5.0.7)
       activesupport (>= 3, < 6)
       redis-store (>= 1.3, < 2)
     redis-namespace (1.6.0)
       redis (>= 3.0.4)
-    redis-rack (2.0.4)
+    redis-rack (2.0.5)
       rack (>= 1.5, < 3)
       redis-store (>= 1.2, < 2)
     redis-rails (5.0.2)
@@ -1197,7 +1197,7 @@ DEPENDENCIES
   rdoc (~> 6.0)
   re2 (~> 1.1.1)
   recaptcha (~> 4.11)
-  redis (~> 3.2)
+  redis (~> 4.0)
   redis-namespace (~> 1.6.0)
   redis-rails (~> 5.0.2)
   request_store (~> 1.3)
diff --git a/changelogs/unreleased/sh-use-redis-caching-store.yml b/changelogs/unreleased/sh-use-redis-caching-store.yml
new file mode 100644
index 00000000000..e61bdb490bc
--- /dev/null
+++ b/changelogs/unreleased/sh-use-redis-caching-store.yml
@@ -0,0 +1,5 @@
+---
+title: Use Rails 5.2 Redis caching store
+merge_request: 30966
+author:
+type: other
diff --git a/config/application.rb b/config/application.rb
index 92240426b5a..21cb79f7851 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -233,7 +233,10 @@ module Gitlab
     end
 
     # Use caching across all environments
+    # Full list of options:
+    # https://api.rubyonrails.org/classes/ActiveSupport/Cache/RedisCacheStore.html#method-c-new
     caching_config_hash = Gitlab::Redis::Cache.params
+    caching_config_hash[:compress] = false
     caching_config_hash[:namespace] = Gitlab::Redis::Cache::CACHE_NAMESPACE
     caching_config_hash[:expires_in] = 2.weeks # Cache should not grow forever
     if Sidekiq.server? # threaded context
@@ -241,7 +244,7 @@ module Gitlab
       caching_config_hash[:pool_timeout] = 1
     end
 
-    config.cache_store = :redis_store, caching_config_hash
+    config.cache_store = :redis_cache_store, caching_config_hash
 
     config.active_job.queue_adapter = :sidekiq
 
-- 
2.30.9