Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
0163e276
Commit
0163e276
authored
Mar 16, 2016
by
Jacob Vosmaer
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Gitlab::Redis connection pool
parent
ba7fcc98
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
23 deletions
+31
-23
config/application.rb
config/application.rb
+2
-2
config/initializers/session_store.rb
config/initializers/session_store.rb
+1
-1
config/initializers/sidekiq.rb
config/initializers/sidekiq.rb
+2
-2
config/mail_room.yml
config/mail_room.yml
+2
-2
lib/gitlab/exclusive_lease.rb
lib/gitlab/exclusive_lease.rb
+3
-1
lib/gitlab/redis.rb
lib/gitlab/redis.rb
+8
-3
lib/tasks/cache.rake
lib/tasks/cache.rake
+13
-12
No files found.
config/application.rb
View file @
0163e276
...
...
@@ -4,7 +4,7 @@ require 'rails/all'
require
'devise'
I18n
.
config
.
enforce_available_locales
=
false
Bundler
.
require
(
:default
,
Rails
.
env
)
require_relative
'../lib/gitlab/redis
_config
'
require_relative
'../lib/gitlab/redis'
module
Gitlab
REDIS_CACHE_NAMESPACE
=
'cache:gitlab'
...
...
@@ -69,7 +69,7 @@ module Gitlab
end
end
redis_config_hash
=
Gitlab
::
Redis
Config
.
redis_store_options
redis_config_hash
=
Gitlab
::
Redis
.
redis_store_options
redis_config_hash
[
:namespace
]
=
REDIS_CACHE_NAMESPACE
redis_config_hash
[
:expires_in
]
=
2
.
weeks
# Cache should not grow forever
config
.
cache_store
=
:redis_store
,
redis_config_hash
...
...
config/initializers/session_store.rb
View file @
0163e276
...
...
@@ -13,7 +13,7 @@ end
if
Rails
.
env
.
test?
Gitlab
::
Application
.
config
.
session_store
:cookie_store
,
key:
"_gitlab_session"
else
redis_config
=
Gitlab
::
Redis
Config
.
redis_store_options
redis_config
=
Gitlab
::
Redis
.
redis_store_options
redis_config
[
:namespace
]
=
'session:gitlab'
Gitlab
::
Application
.
config
.
session_store
(
...
...
config/initializers/sidekiq.rb
View file @
0163e276
...
...
@@ -2,7 +2,7 @@ SIDEKIQ_REDIS_NAMESPACE = 'resque:gitlab'
Sidekiq
.
configure_server
do
|
config
|
config
.
redis
=
{
url:
Gitlab
::
Redis
Config
.
url
,
url:
Gitlab
::
Redis
.
url
,
namespace:
SIDEKIQ_REDIS_NAMESPACE
}
...
...
@@ -29,7 +29,7 @@ end
Sidekiq
.
configure_client
do
|
config
|
config
.
redis
=
{
url:
Gitlab
::
Redis
Config
.
url
,
url:
Gitlab
::
Redis
.
url
,
namespace:
SIDEKIQ_REDIS_NAMESPACE
}
end
config/mail_room.yml
View file @
0163e276
...
...
@@ -2,7 +2,7 @@
<%
require "yaml"
require "json"
require_relative "lib/gitlab/redis
_config
"
require_relative "lib/gitlab/redis"
rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
...
...
@@ -18,7 +18,7 @@ if File.exists?(config_file)
config['mailbox'] = "inbox" if config['mailbox'].nil?
if config['enabled'] && config['address']
redis_url = Gitlab::Redis
Config
.new(rails_env).url
redis_url = Gitlab::Redis.new(rails_env).url
%>
-
:host: <%= config['host'].to_json %>
...
...
lib/gitlab/exclusive_lease.rb
View file @
0163e276
...
...
@@ -43,7 +43,9 @@ module Gitlab
# false if the lease is already taken.
def
try_obtain
# Performing a single SET is atomic
!!
redis
.
set
(
redis_key
,
'1'
,
nx:
true
,
ex:
@timeout
)
Gitlab
::
Redis
.
with
do
|
redis
|
!!
redis
.
set
(
redis_key
,
'1'
,
nx:
true
,
ex:
@timeout
)
end
end
# No #cancel method. See comments above!
...
...
lib/gitlab/redis
_config
.rb
→
lib/gitlab/redis.rb
View file @
0163e276
module
Gitlab
class
Redis
Config
class
Redis
attr_reader
:url
def
self
.
url
new
.
url
@url
||=
new
.
url
end
def
self
.
with
@pool
||=
ConnectionPool
.
new
{
::
Redis
.
new
(
url:
url
)
}
@pool
.
with
{
|
redis
|
yield
redis
}
end
def
self
.
redis_store_options
url
=
new
.
url
redis_config_hash
=
Redis
::
Store
::
Factory
.
extract_host_options_from_uri
(
url
)
redis_config_hash
=
::
Redis
::
Store
::
Factory
.
extract_host_options_from_uri
(
url
)
# Redis::Store does not handle Unix sockets well, so let's do it for them
redis_uri
=
URI
.
parse
(
url
)
if
redis_uri
.
scheme
==
'unix'
...
...
lib/tasks/cache.rake
View file @
0163e276
...
...
@@ -4,18 +4,19 @@ namespace :cache do
desc
"GitLab | Clear redis cache"
task
:clear
=>
:environment
do
redis
=
Redis
.
new
(
url:
Gitlab
::
RedisConfig
.
url
)
cursor
=
REDIS_SCAN_START_STOP
loop
do
cursor
,
keys
=
redis
.
scan
(
cursor
,
match:
"
#{
Gitlab
::
REDIS_CACHE_NAMESPACE
}
*"
,
count:
CLEAR_BATCH_SIZE
)
redis
.
del
(
*
keys
)
if
keys
.
any?
break
if
cursor
==
REDIS_SCAN_START_STOP
Gitlab
::
Redis
.
with
do
|
redis
|
cursor
=
REDIS_SCAN_START_STOP
loop
do
cursor
,
keys
=
redis
.
scan
(
cursor
,
match:
"
#{
Gitlab
::
REDIS_CACHE_NAMESPACE
}
*"
,
count:
CLEAR_BATCH_SIZE
)
redis
.
del
(
*
keys
)
if
keys
.
any?
break
if
cursor
==
REDIS_SCAN_START_STOP
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment