Class: CSC::CSConnector

Inherits:
Object
  • Object
show all
Defined in:
lib/cache-server-connector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCSConnector

Returns a new instance of CSConnector.



14
15
16
17
# File 'lib/cache-server-connector.rb', line 14

def initialize
	@index_type = CSC::COUNT
	@servers = []
end

Instance Attribute Details

#index_type=(value) ⇒ Object (writeonly)

Sets the attribute index_type

Parameters:

  • value

    the value to set the attribute index_type to.



12
13
14
# File 'lib/cache-server-connector.rb', line 12

def index_type=(value)
  @index_type = value
end

Instance Method Details

#add_memcached(host, weight = 1, port = 11211) {|server| ... } ⇒ Object

Yields:

  • (server)


19
20
21
22
23
# File 'lib/cache-server-connector.rb', line 19

def add_memcached(host, weight = 1, port = 11211)
	server = MemcachedServer.new(host, weight, port)
	yield(server) if block_given?
	@servers << server
end

#add_redis(host, weight = 1, port = 6379) {|server| ... } ⇒ Object

Yields:

  • (server)


25
26
27
28
29
# File 'lib/cache-server-connector.rb', line 25

def add_redis(host, weight = 1, port = 6379)
	server = RedisServer.new(host, weight, port)
	yield(server) if block_given?
	@servers << server
end

#next_server(source = '') ⇒ Object



31
32
33
34
35
36
37
# File 'lib/cache-server-connector.rb', line 31

def next_server(source = '')
	case @index_type
		when CSC::COUNT  then next_count_server
		when CSC::HASH   then next_hash_server(source)
		when CSC::WEIGHT then next_weight_server
	end
end