Module: Couchbase::Operations::Delete

Defined in:
lib/couchbase/operations/delete.rb

Instance Method Summary collapse

Instance Method Details

#async_delete(*args, &block) ⇒ Object



72
73
74
75
76
77
# File 'lib/couchbase/operations/delete.rb', line 72

def async_delete(*args, &block)
  key, cas, options = expand_delete_args(args)

  future = client.delete(key)
  register_future(future, { op: :delete }, &block)
end

#delete(key, options = {}) ⇒ true, ...

Delete the specified key

Returns the result of the operation.

Examples:

Delete the key in quiet mode (default)

c.set("foo", "bar")
c.delete("foo")        #=> true
c.delete("foo")        #=> false

Delete the key verbosely

c.set("foo", "bar")
c.delete("foo", :quiet => false)   #=> true
c.delete("foo", :quiet => true)    #=> nil (default behaviour)
c.delete("foo", :quiet => false)   #=> will raise Couchbase::Error::NotFound

Delete the key with version check

ver = c.set("foo", "bar")          #=> 5992859822302167040
c.delete("foo", :cas => 123456)    #=> will raise Couchbase::Error::KeyExists
c.delete("foo", :cas => ver)       #=> true

Options Hash (options):

  • :quiet (true, false) — default: self.quiet

    If set to true, the operation won’t raise error for missing key, it will return nil. Otherwise it will raise error in synchronous mode. In asynchronous mode this option ignored.

  • :cas (Fixnum)

    The CAS value for an object. This value created on the server and is guaranteed to be unique for each value of a given key. This value is used to provide simple optimistic concurrency control when multiple clients or threads try to update/delete an item simultaneously.

Raises:

  • if connection closed (see Bucket#reconnect)

  • when passing the block in synchronous mode

  • on CAS mismatch

  • if key is missing in verbose mode

Parameters:

  • Key used to reference the value.

  • (defaults to: {})

    Options for operation.

Returns:

  • the result of the operation

Since:

  • 1.0.0



62
63
64
65
66
67
68
69
70
# File 'lib/couchbase/operations/delete.rb', line 62

def delete(*args)
  key, cas, options = expand_delete_args(args)

  if key.respond_to?(:to_ary)
    delete_multi(key, options)
  else
    delete_single(key, cas, options)
  end
end