Class: RedisWmrs::Dispatcher

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/redis_wmrs/dispatcher.rb

Constant Summary collapse

MASTER_SLAVE_COMMANDS =
[
  :select, :quit,
].freeze
DEFAULT_SLAVE_COMMANDS =
[
  :info, # :sync,
  :dbsize, :lastsave, :time, :ttl, :pttl, :exists, :keys, :randomkey, :type,
  :get, :mget, :getrange, :getbit, :bitcount, :getset, :strlen, :llen,
  :lindex, :srandmember, :sismember, :smembers, :sdiff, :sinter, :sunion,
  :zcard, :zscore, :zrange, :zrevrange, :zrank, :zrevrank, :zrangebyscore,
  :zrevrangebyscore, :zremrangebyscore, :zcount,
  :hlen, :hget, :hmget, :hexists, :hkeys, :hvals, :hgetall,
  # :watch, :unwatch,
  :echo, :ping
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(master, slave, options) ⇒ Dispatcher

Returns a new instance of Dispatcher.



28
29
30
31
32
# File 'lib/redis_wmrs/dispatcher.rb', line 28

def initialize(master, slave, options)
  @master, @slave = master, slave
  @both_cmds = options[:both] || MASTER_SLAVE_COMMANDS
  @slave_cmds = options[:slave] || DEFAULT_SLAVE_COMMANDS
end

Instance Attribute Details

#masterObject (readonly)

Returns the value of attribute master.



25
26
27
# File 'lib/redis_wmrs/dispatcher.rb', line 25

def master
  @master
end

#optionsObject (readonly)

Returns the value of attribute options.



26
27
28
# File 'lib/redis_wmrs/dispatcher.rb', line 26

def options
  @options
end

#slaveObject (readonly)

Returns the value of attribute slave.



25
26
27
# File 'lib/redis_wmrs/dispatcher.rb', line 25

def slave
  @slave
end

Instance Method Details

#call(command, &block) ⇒ Object



54
55
56
# File 'lib/redis_wmrs/dispatcher.rb', line 54

def call(command, &block)
  __dispatch__(*command){|c|c.call(command, &block)}
end

#call_loop(command, &block) ⇒ Object



58
59
60
# File 'lib/redis_wmrs/dispatcher.rb', line 58

def call_loop(command, &block)
  __dispatch__(*command){|c|c.call_loop(command, &block)}
end

#call_with_timeout(command, timeout, &blk) ⇒ Object



62
63
64
# File 'lib/redis_wmrs/dispatcher.rb', line 62

def call_with_timeout(command, timeout, &blk)
  __dispatch__(*command){|c|c.call_with_timeout(command, timeout, &blk)}
end

#call_without_timeout(command, &blk) ⇒ Object



66
67
68
# File 'lib/redis_wmrs/dispatcher.rb', line 66

def call_without_timeout(command, &blk)
  __dispatch__(*command){|c|c.call_without_timeout(command, &blk)}
end

#connectObject



50
# File 'lib/redis_wmrs/dispatcher.rb', line 50

def connect   ; __both__{|c| c.connect   }; return self; end

#db=(db) ⇒ Object



42
43
44
# File 'lib/redis_wmrs/dispatcher.rb', line 42

def db=(db)
  __both__{|c| c.db = db}; return db
end

#disconnectObject



51
# File 'lib/redis_wmrs/dispatcher.rb', line 51

def disconnect; __both__{|c| c.disconnect}; return self; end

#idsObject



34
35
36
# File 'lib/redis_wmrs/dispatcher.rb', line 34

def ids
  __map__ &:id
end

#locationsObject



38
39
40
# File 'lib/redis_wmrs/dispatcher.rb', line 38

def locations
  __map__ &:location
end

#logger=(v) ⇒ Object



46
47
48
# File 'lib/redis_wmrs/dispatcher.rb', line 46

def logger=(v)
  __both__{|c| c.logger = v}; return v
end

#reconnectObject



52
# File 'lib/redis_wmrs/dispatcher.rb', line 52

def reconnect ; __both__{|c| c.reconnect }; return self; end