Skip to content

Commit

Permalink
Improve Homeland.redis method. Follow Rails way, minimize external …
Browse files Browse the repository at this point in the history
…dependencies

Redis in Rails has built-in ConnectionPool implement, not need extermal gem.
  • Loading branch information
qichunren authored Mar 10, 2024
1 parent 21268d7 commit b071e4d
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/homeland.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ module Homeland
cattr_reader :boot_at

class << self
# Follow Redis offical guides make redis thread safety
# https://github.com/redis/redis-rb#connection-pooling-and-thread-safety

def redis
@redis ||= ConnectionPool::Wrapper.new do
config = Rails.application.config_for(:redis)
Redis.new(url: config["url"], db: 0)
end
Rails.cache.redis.then {|redis| redis }
end

def file_store
Expand Down

2 comments on commit b071e4d

@qichunren
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试没有通过,需要修复

@huacnlee
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不要改,要确保 db 是 0,不然线上会坏掉

Please sign in to comment.