Skip to content

Draft: Add new redis instance

What does this MR do and why?

Part of gitlab-com/gl-infra/scalability#1820 (closed)

How to set up and validate locally

Using the default fallback to Cache

Start the rails console and try the following:

[1] pry(main)> Gitlab::Redis::RepositoryCache.params
=> {:instrumentation_class=>Gitlab::Instrumentation::Redis::RepositoryCache, :path=>"/home/bob/gitlab-development-kit/redis/redis.socket"}
[2] pry(main)> Gitlab::Redis::Cache.params
=> {:instrumentation_class=>Gitlab::Instrumentation::Redis::Cache, :path=>"/home/bob/gitlab-development-kit/redis/redis.socket"}
[3] pry(main)> Gitlab::Redis::Cache.with { |r| r.set('hello', 'world') }
=> "OK"
[4] pry(main)> Gitlab::Redis::RepositoryCache.with { |r| r.get('hello') }
=> "world"
[5] pry(main)> Gitlab::Redis::RepositoryCache.with { |r| r.set('hello', 'mars') }
=> "OK"
[6] pry(main)> Gitlab::Redis::Cache.with { |r| r.get('hello') }
=> "mars"
[7] pry(main)> Gitlab::Redis::RepositoryCache.with { |r| r.get('hello') }
=> "mars"

Notice that both instances use the same database.

Using a separate RepositoryCache configuration

Create a config/redis.repository_cache.yml file with the following contents:

development:
  url: unix:/home/bob/gitlab-development-kit/redis/redis.socket?db=10
test:
  url: unix:/home/bob/gitlab-development-kit/redis/redis.socket?db=100

Restart the rails console. Try the following in a rails console: notice how the 2 databases are split:

[1] pry(main)> Gitlab::Redis::RepositoryCache.params
=> {:instrumentation_class=>Gitlab::Instrumentation::Redis::RepositoryCache, :path=>"/home/bob/gitlab-development-kit/redis/redis.socket", :db=>10}
[2] pry(main)> Gitlab::Redis::Cache.params                                                                                                                 
=> {:instrumentation_class=>Gitlab::Instrumentation::Redis::Cache, :path=>"/home/bob/gitlab-development-kit/redis/redis.socket"}
[3] pry(main)> Gitlab::Redis::Cache.with { |r| r.set('hello', 'world') }
=> "OK"
[5] pry(main)> Gitlab::Redis::RepositoryCache.with { |r| r.get('hello') }                                                                                  
=> nil
[6] pry(main)> Gitlab::Redis::RepositoryCache.with { |r| r.set('hello', 'mars') }                                                                          
=> "OK"
[7] pry(main)> Gitlab::Redis::Cache.with { |r| r.get('hello') }                                                                                            
=> "world"
[8] pry(main)> Gitlab::Redis::RepositoryCache.with { |r| r.get('hello') }                                                                                  
=> "mars"

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Bob Van Landuyt

Merge request reports