Class: Redis::Cluster::Slot
- Inherits:
-
Object
- Object
- Redis::Cluster::Slot
- Defined in:
- lib/redis/cluster/slot.rb
Overview
Keep slot and node key map for Redis Cluster Client
Constant Summary collapse
- ROLE_SLAVE =
'slave'
Instance Method Summary collapse
- #exists?(slot) ⇒ Boolean
- #find_node_key_of_master(slot) ⇒ Object
- #find_node_key_of_slave(slot) ⇒ Object
-
#initialize(available_slots, node_flags = {}, with_replica = false) ⇒ Slot
constructor
A new instance of Slot.
- #put(slot, node_key) ⇒ Object
Constructor Details
#initialize(available_slots, node_flags = {}, with_replica = false) ⇒ Slot
Returns a new instance of Slot.
11 12 13 14 15 |
# File 'lib/redis/cluster/slot.rb', line 11 def initialize(available_slots, node_flags = {}, with_replica = false) @with_replica = with_replica @node_flags = node_flags @map = build_slot_node_key_map(available_slots) end |
Instance Method Details
#exists?(slot) ⇒ Boolean
17 18 19 |
# File 'lib/redis/cluster/slot.rb', line 17 def exists?(slot) @map.key?(slot) end |
#find_node_key_of_master(slot) ⇒ Object
21 22 23 24 25 |
# File 'lib/redis/cluster/slot.rb', line 21 def find_node_key_of_master(slot) return nil unless exists?(slot) @map[slot][:master] end |
#find_node_key_of_slave(slot) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/redis/cluster/slot.rb', line 27 def find_node_key_of_slave(slot) return nil unless exists?(slot) return find_node_key_of_master(slot) if replica_disabled? @map[slot][:slaves].to_a.sample end |
#put(slot, node_key) ⇒ Object
34 35 36 37 |
# File 'lib/redis/cluster/slot.rb', line 34 def put(slot, node_key) assign_node_key(@map, slot, node_key) nil end |