Class: Aerospike::Key

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

Constant Summary collapse

@@digest_pool =
Pool.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ns, set, val, digest = nil, bval: nil, v1_compatible: self.class.v1_compatible?) ⇒ Key

Returns a new instance of Key.



56
57
58
59
60
61
62
63
# File 'lib/aerospike/key.rb', line 56

def initialize(ns, set, val, digest=nil, bval: nil, v1_compatible: self.class.v1_compatible?)
  @namespace = ns
  @set_name = set
  @user_key = Value.of(val)
  check_key!(@namespace, @set_name, @user_key, !digest.nil?)
  @digest = digest || compute_digest(v1_compatible)
  @bval = bval
end

Instance Attribute Details

#digestObject (readonly)

Returns the value of attribute digest.



54
55
56
# File 'lib/aerospike/key.rb', line 54

def digest
  @digest
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



54
55
56
# File 'lib/aerospike/key.rb', line 54

def namespace
  @namespace
end

#set_nameObject (readonly)

Returns the value of attribute set_name.



54
55
56
# File 'lib/aerospike/key.rb', line 54

def set_name
  @set_name
end

Class Method Details

.disable_unsupported_key_warning!(enable_warning = false) ⇒ Object

Keys other than integers, strings and bytes are unsupported and will trigger a warning if used. Starting with v3 the client will raise an error instead of a warning. ref. github.com/aerospike/aerospike-client-ruby/issues/43



47
48
49
# File 'lib/aerospike/key.rb', line 47

def self.disable_unsupported_key_warning!(enable_warning = false)
  @unsupported_key_warning = enable_warning
end

.enable_v1_compatibility!(comp = true) ⇒ Object

enable backwards compatibility with v1 client for integer keys ref. github.com/aerospike/aerospike-client-ruby/pull/34



37
38
39
# File 'lib/aerospike/key.rb', line 37

def self.enable_v1_compatibility!(comp = true)
  @v1_compatibility = !!comp
end

.v1_compatible?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/aerospike/key.rb', line 40

def self.v1_compatible?
  @v1_compatibility
end

.warn_unsupported_key?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/aerospike/key.rb', line 50

def self.warn_unsupported_key?
  @unsupported_key_warning
end

Instance Method Details

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



82
83
84
85
86
# File 'lib/aerospike/key.rb', line 82

def ==(other)
  other && other.is_a?(Key) &&
    other.digest == @digest &&
    other.namespace == @namespace
end

#bvalObject



66
67
68
# File 'lib/aerospike/key.rb', line 66

def bval
  @bval
end

#hashObject



89
90
91
# File 'lib/aerospike/key.rb', line 89

def hash
  @digest.hash
end

#partition_idObject



93
94
95
# File 'lib/aerospike/key.rb', line 93

def partition_id
  (@digest[0..3].unpack(Partition::UNPACK_FORMAT)[0] & 0xFFFF) % Node::PARTITIONS
end

#to_sObject



70
71
72
# File 'lib/aerospike/key.rb', line 70

def to_s
  "#{@namespace}:#{@set_name}:#{@user_key}:#{@digest.nil? ? '' : @digest.bytes}"
end

#user_keyObject



74
75
76
# File 'lib/aerospike/key.rb', line 74

def user_key
  @user_key.get if @user_key
end

#user_key_as_valueObject



78
79
80
# File 'lib/aerospike/key.rb', line 78

def user_key_as_value
  @user_key
end