Class: SlateDb::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/slatedb/transaction.rb

Instance Method Summary collapse

Instance Method Details

#delete(key) ⇒ void

This method returns an undefined value.

Delete a key within the transaction.

Parameters:

  • key (String)

    The key to delete



46
47
48
# File 'lib/slatedb/transaction.rb', line 46

def delete(key)
  _delete(key)
end

#get(key, durability_filter: nil, dirty: nil, cache_blocks: nil) ⇒ String?

Get a value by key within the transaction.

Parameters:

  • key (String)

    The key to look up

  • durability_filter (String, nil) (defaults to: nil)

    Filter by durability level

  • dirty (Boolean, nil) (defaults to: nil)

    Whether to include uncommitted data

  • cache_blocks (Boolean, nil) (defaults to: nil)

    Whether to cache blocks

Returns:

  • (String, nil)

    The value, or nil if not found



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/slatedb/transaction.rb', line 13

def get(key, durability_filter: nil, dirty: nil, cache_blocks: nil)
  opts = {}
  opts[:durability_filter] = durability_filter.to_s if durability_filter
  opts[:dirty] = dirty unless dirty.nil?
  opts[:cache_blocks] = cache_blocks unless cache_blocks.nil?

  if opts.empty?
    _get(key)
  else
    _get_with_options(key, opts)
  end
end

#put(key, value, ttl: nil) ⇒ void

This method returns an undefined value.

Store a key-value pair within the transaction.

Parameters:

  • key (String)

    The key to store

  • value (String)

    The value to store

  • ttl (Integer, nil) (defaults to: nil)

    Time-to-live in milliseconds



33
34
35
36
37
38
39
# File 'lib/slatedb/transaction.rb', line 33

def put(key, value, ttl: nil)
  if ttl
    _put_with_options(key, value, { ttl: ttl })
  else
    _put(key, value)
  end
end

#scan(start_key, end_key = nil, durability_filter: nil, dirty: nil, read_ahead_bytes: nil, cache_blocks: nil, max_fetch_tasks: nil) ⇒ Iterator

Scan a range of keys within the transaction.

Parameters:

  • start_key (String)

    The start key (inclusive)

  • end_key (String, nil) (defaults to: nil)

    The end key (exclusive)

Returns:

  • (Iterator)

    An iterator over key-value pairs



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/slatedb/transaction.rb', line 56

def scan(start_key, end_key = nil, durability_filter: nil, dirty: nil,
         read_ahead_bytes: nil, cache_blocks: nil, max_fetch_tasks: nil, &)
  opts = {}
  opts[:durability_filter] = durability_filter.to_s if durability_filter
  opts[:dirty] = dirty unless dirty.nil?
  opts[:read_ahead_bytes] = read_ahead_bytes if read_ahead_bytes
  opts[:cache_blocks] = cache_blocks unless cache_blocks.nil?
  opts[:max_fetch_tasks] = max_fetch_tasks if max_fetch_tasks

  iter = if opts.empty?
           _scan(start_key, end_key)
         else
           _scan_with_options(start_key, end_key, opts)
         end

  if block_given?
    iter.each(&)
  else
    iter
  end
end