Class: Etcdv3::Namespace::KV

Inherits:
Object
  • Object
show all
Includes:
Requests, Utilities, GRPC::Core::TimeConsts
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/kv.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/kv/requests.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/kv/transaction.rb

Defined Under Namespace

Modules: Requests Classes: Transaction

Constant Summary

Constants included from Requests

Requests::SORT_ORDER, Requests::SORT_TARGET

Instance Method Summary collapse

Methods included from GRPC::Core::TimeConsts

from_relative_time

Methods included from Utilities

#delete_prefix, #prepend_prefix, #strip_prefix, #strip_prefix_from_events, #strip_prefix_from_lock

Methods included from Requests

#del_request, #get_request, #put_request

Constructor Details

#initialize(hostname, credentials, timeout, namespace, metadata = {}) ⇒ KV

Returns a new instance of KV.



7
8
9
10
11
12
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/kv.rb', line 7

def initialize(hostname, credentials, timeout, namespace, ={})
  @stub = Etcdserverpb::KV::Stub.new(hostname, credentials)
  @timeout = timeout
  @namespace = namespace
  @metadata = 
end

Instance Method Details

#del(key, range_end: '', timeout: nil) ⇒ Object



20
21
22
23
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/kv.rb', line 20

def del(key, range_end: '', timeout: nil)
  resp = @stub.delete_range(del_request(key, range_end), metadata: @metadata, deadline: deadline(timeout))
  strip_prefix(@namespace, resp)
end

#get(key, opts = {}) ⇒ Object



14
15
16
17
18
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/kv.rb', line 14

def get(key, opts={})
  timeout = opts.delete(:timeout)
  resp = @stub.range(get_request(key, opts), metadata: @metadata, deadline: deadline(timeout))
  strip_prefix(@namespace, resp)
end

#put(key, value, lease: nil, timeout: nil) ⇒ Object



25
26
27
28
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/kv.rb', line 25

def put(key, value, lease: nil, timeout: nil)
  resp = @stub.put(put_request(key, value, lease), metadata: @metadata, deadline: deadline(timeout))
  strip_prefix(@namespace, resp)
end

#transaction(block, timeout: nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/etcdv3-0.11.5/lib/etcdv3/namespace/kv.rb', line 30

def transaction(block, timeout: nil)
  txn = Etcdv3::Namespace::KV::Transaction.new(@namespace)
  block.call(txn)
  request = Etcdserverpb::TxnRequest.new(
    compare: txn.compare,
    success: generate_request_ops(txn.success),
    failure: generate_request_ops(txn.failure),
  )
  resp = @stub.txn(request, metadata: @metadata, deadline: deadline(timeout))
  strip_prefix(@namespace, resp)
end