Class: Aerospike::Partition

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

Overview

:nodoc:

Constant Summary collapse

UNPACK_FORMAT =
'l<'

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.



27
28
29
30
31
32
# File 'lib/aerospike/cluster/partition.rb', line 27

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

  self
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

#partition_idObject (readonly)

Returns the value of attribute partition_id.



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

def partition_id
  @partition_id
end

Class Method Details

.new_by_key(key) ⇒ Object



34
35
36
37
38
39
# File 'lib/aerospike/cluster/partition.rb', line 34

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

Instance Method Details

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



45
46
47
48
# File 'lib/aerospike/cluster/partition.rb', line 45

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

#hashObject



51
52
53
# File 'lib/aerospike/cluster/partition.rb', line 51

def hash
  to_s.hash
end

#to_sObject



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

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