Module: Couchbase::Operations::Delete

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

Instance Method Summary collapse

Instance Method Details

#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

Parameters:

  • key (String, Symbol)

    Key used to reference the value.

  • options (Hash) (defaults to: {})

    Options for operation.

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.

Returns:

  • (true, false, Hash<String, Boolean>)

    the result of the operation

Raises:

Since:

  • 1.0.0



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

def delete(*args, &block)
  sync_block_error if !async? && block_given?
  key, options = expand_get_args(args)
  key, cas     = delete_args_parser(key)

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