Class: Couchbase::Options::Increment

Inherits:
Base
  • Object
show all
Defined in:
lib/couchbase/options.rb

Overview

Constant Summary collapse

DEFAULT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Increment.new.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#client_context, #parent_span, #retry_strategy, #timeout

Instance Method Summary collapse

Constructor Details

#initialize(delta: 1, initial: nil, expiry: nil, durability_level: :none, replicate_to: :none, persist_to: :none, timeout: nil, retry_strategy: nil, client_context: nil, parent_span: nil) {|self| ... } ⇒ Increment

Creates an instance of options for BinaryCollection#increment

Parameters:

  • delta (Integer) (defaults to: 1)

    the delta for the operation

  • initial (Integer) (defaults to: nil)

    if present, holds the initial value

  • expiry (Integer, #in_seconds, Time, nil) (defaults to: nil)

    if set, holds the expiration for the operation

  • durability_level (Symbol) (defaults to: :none)

    level of durability

    :none

    no enhanced durability required for the mutation

    :majority

    the mutation must be replicated to a majority of the Data Service nodes (that is, held in the memory allocated to the bucket)

    :majority_and_persist_to_active

    The mutation must be replicated to a majority of the Data Service nodes. Additionally, it must be persisted (that is, written and synchronised to disk) on the node hosting the active partition (vBucket) for the data.

    :persist_to_majority

    The mutation must be persisted to a majority of the Data Service nodes. Accordingly, it will be written to disk on those nodes.

  • replicate_to (Symbol) (defaults to: :none)

    number of nodes to replicate

    :none

    do not apply any replication requirements.

    :one

    wait for replication to at least one node.

    :two

    wait for replication to at least two nodes.

    :three

    wait for replication to at least three nodes.

  • persist_to (Symbol) (defaults to: :none)

    number of nodes to persist

    :none

    do not apply any persistence requirements.

    :active

    wait for persistence to active node

    :one

    wait for persistence to at least one node.

    :two

    wait for persistence to at least two nodes.

    :three

    wait for persistence to at least three nodes.

    :four

    wait for persistence to four nodes (active and replicas).

  • timeout (Integer, #in_milliseconds, nil) (defaults to: nil)
  • retry_strategy (Proc, nil) (defaults to: nil)

    the custom retry strategy, if set

  • client_context (Hash, nil) (defaults to: nil)

    the client context data, if set

  • parent_span (Span, nil) (defaults to: nil)

    if set holds the parent span, that should be used for this request

Yield Parameters:

Raises:

  • (ArgumentError)


1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
# File 'lib/couchbase/options.rb', line 1405

def initialize(delta: 1,
               initial: nil,
               expiry: nil,
               durability_level: :none,
               replicate_to: :none,
               persist_to: :none,
               timeout: nil,
               retry_strategy: nil,
               client_context: nil,
               parent_span: nil)
  raise ArgumentError, "the delta cannot be less than 0" if delta.negative?

  super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
  @delta = delta
  @initial = initial
  @expiry = expiry
  if durability_level != :none && (replicate_to != :none || persist_to != :none)
    raise ArgumentError, "durability_level conflicts with replicate_to and persist_to options"
  end

  @persist_to = persist_to
  @replicate_to = replicate_to
  @durability_level = durability_level
  yield self if block_given?
end

Instance Attribute Details

#deltaInteger

Returns:

  • (Integer)


1363
1364
1365
# File 'lib/couchbase/options.rb', line 1363

def delta
  @delta
end

#durability_levelSymbol

Returns:

  • (Symbol)


1366
1367
1368
# File 'lib/couchbase/options.rb', line 1366

def durability_level
  @durability_level
end

#expiryInteger, #in_seconds

Returns:

  • (Integer, #in_seconds)


1365
1366
1367
# File 'lib/couchbase/options.rb', line 1365

def expiry
  @expiry
end

#initialInteger

Returns:

  • (Integer)


1364
1365
1366
# File 'lib/couchbase/options.rb', line 1364

def initial
  @initial
end

Instance Method Details

#to_backendObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
# File 'lib/couchbase/options.rb', line 1439

def to_backend
  {
    timeout: Utils::Time.extract_duration(@timeout),
    delta: @delta,
    initial_value: @initial,
    expiry: Utils::Time.extract_expiry_time(@expiry),
    durability_level: @durability_level,
    persist_to: @persist_to,
    replicate_to: @replicate_to,
  }
end