Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
0163e276
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0163e276
编写于
3月 16, 2016
作者:
J
Jacob Vosmaer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Gitlab::Redis connection pool
上级
ba7fcc98
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
31 addition
and
23 deletion
+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
未找到文件。
config/application.rb
浏览文件 @
0163e276
...
@@ -4,7 +4,7 @@ require 'rails/all'
...
@@ -4,7 +4,7 @@ require 'rails/all'
require
'devise'
require
'devise'
I18n
.
config
.
enforce_available_locales
=
false
I18n
.
config
.
enforce_available_locales
=
false
Bundler
.
require
(
:default
,
Rails
.
env
)
Bundler
.
require
(
:default
,
Rails
.
env
)
require_relative
'../lib/gitlab/redis
_config
'
require_relative
'../lib/gitlab/redis'
module
Gitlab
module
Gitlab
REDIS_CACHE_NAMESPACE
=
'cache:gitlab'
REDIS_CACHE_NAMESPACE
=
'cache:gitlab'
...
@@ -69,7 +69,7 @@ module Gitlab
...
@@ -69,7 +69,7 @@ module Gitlab
end
end
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
[
:namespace
]
=
REDIS_CACHE_NAMESPACE
redis_config_hash
[
:expires_in
]
=
2
.
weeks
# Cache should not grow forever
redis_config_hash
[
:expires_in
]
=
2
.
weeks
# Cache should not grow forever
config
.
cache_store
=
:redis_store
,
redis_config_hash
config
.
cache_store
=
:redis_store
,
redis_config_hash
...
...
config/initializers/session_store.rb
浏览文件 @
0163e276
...
@@ -13,7 +13,7 @@ end
...
@@ -13,7 +13,7 @@ end
if
Rails
.
env
.
test?
if
Rails
.
env
.
test?
Gitlab
::
Application
.
config
.
session_store
:cookie_store
,
key:
"_gitlab_session"
Gitlab
::
Application
.
config
.
session_store
:cookie_store
,
key:
"_gitlab_session"
else
else
redis_config
=
Gitlab
::
Redis
Config
.
redis_store_options
redis_config
=
Gitlab
::
Redis
.
redis_store_options
redis_config
[
:namespace
]
=
'session:gitlab'
redis_config
[
:namespace
]
=
'session:gitlab'
Gitlab
::
Application
.
config
.
session_store
(
Gitlab
::
Application
.
config
.
session_store
(
...
...
config/initializers/sidekiq.rb
浏览文件 @
0163e276
...
@@ -2,7 +2,7 @@ SIDEKIQ_REDIS_NAMESPACE = 'resque:gitlab'
...
@@ -2,7 +2,7 @@ SIDEKIQ_REDIS_NAMESPACE = 'resque:gitlab'
Sidekiq
.
configure_server
do
|
config
|
Sidekiq
.
configure_server
do
|
config
|
config
.
redis
=
{
config
.
redis
=
{
url:
Gitlab
::
Redis
Config
.
url
,
url:
Gitlab
::
Redis
.
url
,
namespace:
SIDEKIQ_REDIS_NAMESPACE
namespace:
SIDEKIQ_REDIS_NAMESPACE
}
}
...
@@ -29,7 +29,7 @@ end
...
@@ -29,7 +29,7 @@ end
Sidekiq
.
configure_client
do
|
config
|
Sidekiq
.
configure_client
do
|
config
|
config
.
redis
=
{
config
.
redis
=
{
url:
Gitlab
::
Redis
Config
.
url
,
url:
Gitlab
::
Redis
.
url
,
namespace:
SIDEKIQ_REDIS_NAMESPACE
namespace:
SIDEKIQ_REDIS_NAMESPACE
}
}
end
end
config/mail_room.yml
浏览文件 @
0163e276
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<%
<%
require "yaml"
require "yaml"
require "json"
require "json"
require_relative "lib/gitlab/redis
_config
"
require_relative "lib/gitlab/redis"
rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
...
@@ -18,7 +18,7 @@ if File.exists?(config_file)
...
@@ -18,7 +18,7 @@ if File.exists?(config_file)
config['mailbox'] = "inbox" if config['mailbox'].nil?
config['mailbox'] = "inbox" if config['mailbox'].nil?
if config['enabled'] && config['address']
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 %>
:host: <%= config['host'].to_json %>
...
...
lib/gitlab/exclusive_lease.rb
浏览文件 @
0163e276
...
@@ -43,7 +43,9 @@ module Gitlab
...
@@ -43,7 +43,9 @@ module Gitlab
# false if the lease is already taken.
# false if the lease is already taken.
def
try_obtain
def
try_obtain
# Performing a single SET is atomic
# 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
end
# No #cancel method. See comments above!
# No #cancel method. See comments above!
...
...
lib/gitlab/redis
_config
.rb
→
lib/gitlab/redis.rb
浏览文件 @
0163e276
module
Gitlab
module
Gitlab
class
Redis
Config
class
Redis
attr_reader
:url
attr_reader
:url
def
self
.
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
end
def
self
.
redis_store_options
def
self
.
redis_store_options
url
=
new
.
url
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::Store does not handle Unix sockets well, so let's do it for them
redis_uri
=
URI
.
parse
(
url
)
redis_uri
=
URI
.
parse
(
url
)
if
redis_uri
.
scheme
==
'unix'
if
redis_uri
.
scheme
==
'unix'
...
...
lib/tasks/cache.rake
浏览文件 @
0163e276
...
@@ -4,18 +4,19 @@ namespace :cache do
...
@@ -4,18 +4,19 @@ namespace :cache do
desc
"GitLab | Clear redis cache"
desc
"GitLab | Clear redis cache"
task
:clear
=>
:environment
do
task
:clear
=>
:environment
do
redis
=
Redis
.
new
(
url:
Gitlab
::
RedisConfig
.
url
)
Gitlab
::
Redis
.
with
do
|
redis
|
cursor
=
REDIS_SCAN_START_STOP
cursor
=
REDIS_SCAN_START_STOP
loop
do
loop
do
cursor
,
keys
=
redis
.
scan
(
cursor
,
keys
=
redis
.
scan
(
cursor
,
cursor
,
match:
"
#{
Gitlab
::
REDIS_CACHE_NAMESPACE
}
*"
,
match:
"
#{
Gitlab
::
REDIS_CACHE_NAMESPACE
}
*"
,
count:
CLEAR_BATCH_SIZE
count:
CLEAR_BATCH_SIZE
)
)
redis
.
del
(
*
keys
)
if
keys
.
any?
redis
.
del
(
*
keys
)
if
keys
.
any?
break
if
cursor
==
REDIS_SCAN_START_STOP
break
if
cursor
==
REDIS_SCAN_START_STOP
end
end
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录