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 => 40,
  :size => 1
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ShardInfo

Returns a new instance of ShardInfo.



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

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



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

def create_resource
  RedisClient.new(@options)
end

#to_sObject



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

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