Class: RedisProxyServer

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/redis-proxy/redis_proxy_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(redis_config) ⇒ RedisProxyServer

Returns a new instance of RedisProxyServer.



3
4
5
6
# File 'lib/redis-proxy/redis_proxy_server.rb', line 3

def initialize(redis_config)
  @@redis_config = redis_config
  @@default_node = redis_config[:nodes].first
end

Instance Method Details

#receive_data(data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/redis-proxy/redis_proxy_server.rb', line 8

def receive_data(data)

  if @proxy.nil?
    (@buffer ||= "") << data
    if @buffer =~ /\r\n/
      @proxy = EventMachine.connect @@default_node[:host], @@default_node[:port], RedisConnection, @@redis_config, self, data
    end
  else
    @proxy.send_data data
  end
end

#unbindObject



20
21
22
23
# File 'lib/redis-proxy/redis_proxy_server.rb', line 20

def unbind
  puts "RedisProxy: unbind"
  @proxy.client_unbind
end