Class: Aerospike::Key
- Inherits:
-
Object
- Object
- Aerospike::Key
- Defined in:
- lib/aerospike/key.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#set_name ⇒ Object
readonly
Returns the value of attribute set_name.
Class Method Summary collapse
-
.disable_unsupported_key_warning!(enable_warning = false) ⇒ Object
Keys other than integers, strings and bytes are unsupported and will trigger a warning if used.
-
.enable_v1_compatibility!(comp = true) ⇒ Object
enable backwards compatibility with v1 client for integer keys ref.
- .v1_compatible? ⇒ Boolean
- .warn_unsupported_key? ⇒ Boolean
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #bval ⇒ Object
- #hash ⇒ Object
-
#initialize(ns, set, val, digest = nil, bval: nil, v1_compatible: self.class.v1_compatible?) ⇒ Key
constructor
A new instance of Key.
- #partition_id ⇒ Object
- #to_s ⇒ Object
- #user_key ⇒ Object
- #user_key_as_value ⇒ Object
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
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
54 55 56 |
# File 'lib/aerospike/key.rb', line 54 def digest @digest end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
54 55 56 |
# File 'lib/aerospike/key.rb', line 54 def namespace @namespace end |
#set_name ⇒ Object (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
40 41 42 |
# File 'lib/aerospike/key.rb', line 40 def self.v1_compatible? @v1_compatibility end |
.warn_unsupported_key? ⇒ 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 |
#bval ⇒ Object
66 67 68 |
# File 'lib/aerospike/key.rb', line 66 def bval @bval end |
#hash ⇒ Object
89 90 91 |
# File 'lib/aerospike/key.rb', line 89 def hash @digest.hash end |
#partition_id ⇒ Object
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_s ⇒ Object
70 71 72 |
# File 'lib/aerospike/key.rb', line 70 def to_s "#{@namespace}:#{@set_name}:#{@user_key}:#{@digest.nil? ? '' : @digest.bytes}" end |
#user_key ⇒ Object
74 75 76 |
# File 'lib/aerospike/key.rb', line 74 def user_key @user_key.get if @user_key end |
#user_key_as_value ⇒ Object
78 79 80 |
# File 'lib/aerospike/key.rb', line 78 def user_key_as_value @user_key end |