Class: Aerospike::Partition

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/cluster/partition.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, partition_id) ⇒ Partition

Returns a new instance of Partition.



24
25
26
27
28
29
# File 'lib/aerospike/cluster/partition.rb', line 24

def initialize(namespace, partition_id)
  @namespace = namespace
  @partition_id = partition_id

  self
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



22
23
24
# File 'lib/aerospike/cluster/partition.rb', line 22

def namespace
  @namespace
end

#partition_idObject (readonly)

Returns the value of attribute partition_id.



22
23
24
# File 'lib/aerospike/cluster/partition.rb', line 22

def partition_id
  @partition_id
end

Class Method Details

.new_by_key(key) ⇒ Object



31
32
33
34
35
36
# File 'lib/aerospike/cluster/partition.rb', line 31

def self.new_by_key(key)
  Partition.new(
    key.namespace,
    (key.digest[0..3].unpack('l<')[0] & 0xFFFF) % Node::PARTITIONS
  )
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



42
43
44
45
# File 'lib/aerospike/cluster/partition.rb', line 42

def ==(other)
  other && other.is_a?(Partition) && @partition_id == other.partition_id &&
    @namespace == other.namespace
end

#hashObject



48
49
50
# File 'lib/aerospike/cluster/partition.rb', line 48

def hash
  to_s.hash
end

#to_sObject



38
39
40
# File 'lib/aerospike/cluster/partition.rb', line 38

def to_s
  "#{@namespace}:#{partition_id}"
end