Skip to content

Instantly share code, notes, and snippets.

@eccyan
Created May 7, 2014 07:26
Show Gist options
  • Save eccyan/0de1dafc1ea00e6f13f9 to your computer and use it in GitHub Desktop.
Save eccyan/0de1dafc1ea00e6f13f9 to your computer and use it in GitHub Desktop.
Rails でサクッと Redis を Master/Slave 構成にする ref: http://qiita.com/eccyan/items/7a7bdeb693f4df16b8f9
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