Module: Couchbase::Operations::Unlock

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

Instance Method Summary collapse

Instance Method Details

#async_unlock(key, options = {}) ⇒ Object



84
85
86
# File 'lib/couchbase/operations/unlock.rb', line 84

def async_unlock(key, options = {})

end

#unlock(key, options = {}) ⇒ true, false #unlock(keys) {|ret| ... } ⇒ Hash

Unlock key

The unlock method allow you to unlock key once locked by Bucket#get with :lock option.

Overloads:

  • #unlock(key, options = {}) ⇒ true, false

    Returns true if the operation was successful and false otherwise.

    Examples:

    Unlock the single key

    val, _, cas = c.get("foo", :lock => true, :extended => true)
    c.unlock("foo", :cas => cas)

    Parameters:

    • key (String, Symbol)

      Key used to reference the value.

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

      Options for operation.

    Options Hash (options):

    • :cas (Fixnum)

      The CAS value must match the current one from the storage.

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

      If set to true, the operation won’t raise error for missing key, it will return nil.

    Returns:

    • (true, false)

      true if the operation was successful and false otherwise.

    Raises:

  • #unlock(keys) {|ret| ... } ⇒ Hash

    Returns Mapping keys to result of unlock operation (true if the operation was successful and false otherwise).

    Examples:

    Unlock several keys

    c.unlock("foo" => cas1, :bar => cas2) #=> {"foo" => true, "bar" => true}

    Unlock several values in async mode

    c.run do
      c.unlock("foo" => 10, :bar => 20) do |ret|
         ret.operation   #=> :unlock
         ret.success?    #=> true
         ret.key         #=> "foo" and "bar" in separate calls
      end
    end

    Parameters:

    • keys (Hash)

      The Hash where keys represent the keys in the database, values – the CAS for corresponding key.

    Yield Parameters:

    • ret (Result)

      the result of operation for each key in asynchronous mode (valid attributes: error, operation, key).

    Returns:

    • (Hash)

      Mapping keys to result of unlock operation (true if the operation was successful and false otherwise)

Since:

  • 1.2.0



75
76
77
78
79
80
81
82
# File 'lib/couchbase/operations/unlock.rb', line 75

def unlock(key, options = {})
  cas = options.respond_to?(:to_hash) ? options[:cas] : options
  if client.unlock(key.to_s, cas)
    true
  else
    raise Couchbase::Error::TemporaryFail.new
  end
end