Class: RedisCluster::Node
- Inherits:
-
Object
- Object
- RedisCluster::Node
- Defined in:
- lib/redis_cluster/node.rb
Instance Attribute Summary collapse
-
#slots ⇒ Object
slots is a range array: [1..100, 300..500].
Class Method Summary collapse
Instance Method Summary collapse
- #asking ⇒ Object
- #connection ⇒ Object
- #execute(method, args) ⇒ Object
- #has_slot?(slot) ⇒ Boolean
- #host_hash ⇒ Object
-
#initialize(opts) ⇒ Node
constructor
basic requires: xxx.xxx.xx.xx, port: xxx redis cluster don’t support select db, use default 0.
- #name ⇒ Object
Constructor Details
#initialize(opts) ⇒ Node
basic requires:
{host: xxx.xxx.xx.xx, port: xxx}
redis cluster don’t support select db, use default 0
12 13 14 15 |
# File 'lib/redis_cluster/node.rb', line 12 def initialize(opts) = opts @slots = [] end |
Instance Attribute Details
#slots ⇒ Object
slots is a range array: [1..100, 300..500]
5 6 7 |
# File 'lib/redis_cluster/node.rb', line 5 def slots @slots end |
Class Method Details
.redis(options) ⇒ Object
41 42 43 |
# File 'lib/redis_cluster/node.rb', line 41 def self.redis() ::Redis.new() end |
Instance Method Details
#asking ⇒ Object
29 30 31 |
# File 'lib/redis_cluster/node.rb', line 29 def asking execute(:asking) end |
#connection ⇒ Object
37 38 39 |
# File 'lib/redis_cluster/node.rb', line 37 def connection @connection ||= self.class.redis() end |
#execute(method, args) ⇒ Object
33 34 35 |
# File 'lib/redis_cluster/node.rb', line 33 def execute(method, args) connection.send(method, *args) end |
#has_slot?(slot) ⇒ Boolean
25 26 27 |
# File 'lib/redis_cluster/node.rb', line 25 def has_slot?(slot) slots.any? {|range| range.include? slot } end |
#host_hash ⇒ Object
21 22 23 |
# File 'lib/redis_cluster/node.rb', line 21 def host_hash {host: [:host], port: [:port]} end |
#name ⇒ Object
17 18 19 |
# File 'lib/redis_cluster/node.rb', line 17 def name "#{@options[:host]}:#{@options[:port]}" end |