Sha256: f0d4d907607231eed4e5527a94a6972d3465a6debc80ef564a9a65c0b87a1139
Contents?: true
Size: 1.8 KB
Versions: 12
Compression:
Stored size: 1.8 KB
Contents
class Etcdv3::KV class Transaction include Etcdv3::KV::Requests # Available comparison identifiers. COMPARISON_IDENTIFIERS = { equal: 0, greater: 1, less: 2, not_equal: 3 } # Available targets to compare with. TARGETS = { version: 0, create_revision: 1, mod_revision: 2, value: 3 } attr_writer :compare, :success, :failure def initialize; end def compare @compare ||= [] end def success @success ||= [] end def failure @failure ||=[] end # Request Operations # txn.put('my', 'key', lease_id: 1) def put(key, value, lease=nil) put_request(key, value, lease) end # txn.get('key') def get(key, opts={}) get_request(key, opts) end # txn.del('key') def del(key, range_end='') del_request(key, range_end) end ### Compare Operations # txn.version('names', :greater, 0 ) def version(key, compare_type, value) generate_compare(:version, key, compare_type, value) end # txn.value('names', :equal, 'wowza' ) def value(key, compare_type, value) generate_compare(:value, key, compare_type, value) end # txn.mod_revision('names', :not_equal, 0) def mod_revision(key, compare_type, value) generate_compare(:mod_revision, key, compare_type, value) end # txn.create_revision('names', :less, 10) def create_revision(key, compare_type, value) generate_compare(:create_revision, key, compare_type, value) end private def generate_compare(target_union, key, compare_type, value) Etcdserverpb::Compare.new( key: key, result: COMPARISON_IDENTIFIERS[compare_type], target: TARGETS[target_union], target_union => value ) end end end
Version data entries
12 entries across 12 versions & 2 rubygems