Skip to content
Browse files

minor refactorings; still no real tests :)

  • Loading branch information...
1 parent a1048ad commit 9fa38f07ab13a8deb496dfeccc7b480e0e5ecf89 @levicook committed Feb 14, 2010
Showing with 8 additions and 13 deletions.
  1. +8 −13 lib/memodis/dist_cache.rb
View
21 lib/memodis/dist_cache.rb
@@ -16,7 +16,7 @@ def initialize(options)
:timeout => options[:timeout],
})
- @slaves = options.fetch(:slaves, []).map do |h|
+ @slaves = options[:slaves].map do |h|
host, port = h.split(':')
Redis.new({
:db => options[:db],
@@ -52,18 +52,13 @@ def [] key
private
def indexed_slaves
- @indexed_slaves ||= begin
- indexed_slaves = {}
- #indexed_slaves.default = @master
- @slaves.each do |slave|
- slave_info = slave.info
- master_host = slave_info[:master_host]
- master_port = slave_info[:master_port]
- key = "%s:%s" % [master_host, master_port]
- indexed_slaves[key] = slave
- end
- indexed_slaves
- end
+ @indexed_slaves ||= @slaves.inject(Hash.new) do |index, slave|
+ slave_info = slave.info
+ master_host = slave_info[:master_host]
+ master_port = slave_info[:master_port]
+ index["#{master_host}:#{master_port}"] = slave
+ index
+ end
end
def get key

0 comments on commit 9fa38f0

Please sign in to comment.
Something went wrong with that request. Please try again.