Class: RedisSsdbProxy::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_ssdb_proxy/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
# File 'lib/redis_ssdb_proxy/client.rb', line 8

def initialize(args)
  self.master, self.slave = args.fetch(:master), args.fetch(:slave)
  if [:master, :slave].include? args[:ssdb]
    delegate_ssdb_unsupport self.send(args[:ssdb])
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

all write opreate send to master slave both



96
97
98
99
100
101
102
103
104
# File 'lib/redis_ssdb_proxy/client.rb', line 96

def method_missing(name, *args, &block)
  if master.respond_to?(name)
    self.class.send(:send_to_both, name)
    slave.send(name, *args, &block)
    master.send(name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#masterObject

Returns the value of attribute master.



6
7
8
# File 'lib/redis_ssdb_proxy/client.rb', line 6

def master
  @master
end

#slaveObject

Returns the value of attribute slave.



6
7
8
# File 'lib/redis_ssdb_proxy/client.rb', line 6

def slave
  @slave
end

Instance Method Details

#delegate_ssdb_unsupport(redis_client) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/redis_ssdb_proxy/client.rb', line 15

def delegate_ssdb_unsupport(redis_client)
  redis_client.instance_eval do
    def sadd(key, *args)
      zadd(key, args.map{ |arg|
        [Time.now.to_i, arg]
      })
    end

    def srem(*args)
      zrem(*args)
    end
  end
end