Created
May 7, 2014 07:26
-
-
Save eccyan/0de1dafc1ea00e6f13f9 to your computer and use it in GitHub Desktop.
Rails でサクッと Redis を Master/Slave 構成にする ref: http://qiita.com/eccyan/items/7a7bdeb693f4df16b8f9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Redis | |
class Client | |
def call(command, &block) | |
master_host = MASTER_HOST_URI | |
slave_host = SLAVE_HOST_URI | |
# Slave に向けたいお好きなコマンドを登録 | |
slave_commands = [:get, :hget, :hgetall] | |
disconnect | |
@options[:host] = if slave_commands.include?(command[0]) | |
slave_host | |
else | |
master_host | |
end | |
connect | |
reply = process([command]) { read } | |
raise reply if reply.is_a?(CommandError) | |
if block | |
block.call(reply) | |
else | |
reply | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment