Class: Xunch::ShardInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/xunch/shard/shard_info.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :host => "127.0.0.1",
  :port => 6379,
  :name => nil,
  :password => nil,
  :timeout => nil,
  :db => 0,
  :weight => 1
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ShardInfo

Returns a new instance of ShardInfo.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/xunch/shard/shard_info.rb', line 15

def initialize(options)
  raise "initialize ShardInfo error, options can not be nil." if options == nil
  @options = DEFAULT_OPTIONS.merge(options)

  @host = options[:host]
  @port = options[:port]
  @name = options[:name]
  @password = options[:password]
  @timeout = options[:timeout]
  @db = options[:db]
  @weight = options[:weight]
end

Instance Attribute Details

#databaseObject

Returns the value of attribute database.



3
4
5
# File 'lib/xunch/shard/shard_info.rb', line 3

def database
  @database
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/xunch/shard/shard_info.rb', line 3

def host
  @host
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/xunch/shard/shard_info.rb', line 3

def name
  @name
end

#passwordObject

Returns the value of attribute password.



3
4
5
# File 'lib/xunch/shard/shard_info.rb', line 3

def password
  @password
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/xunch/shard/shard_info.rb', line 3

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout.



3
4
5
# File 'lib/xunch/shard/shard_info.rb', line 3

def timeout
  @timeout
end

#weightObject

Returns the value of attribute weight.



3
4
5
# File 'lib/xunch/shard/shard_info.rb', line 3

def weight
  @weight
end

Instance Method Details

#create_resourceObject



28
29
30
# File 'lib/xunch/shard/shard_info.rb', line 28

def create_resource
  RedisClient.new(@options)
end

#to_sObject



32
33
34
# File 'lib/xunch/shard/shard_info.rb', line 32

def to_s
  "#{@host}:#{@port}::#{@db}*#{@weight}";
end