def get_and_lock(self, id, # type: str expiration, # type: int *options, # type: GetAndLockOptions **kwargs ): # type: (...)->GetResult final_options=forward_args(kwargs, *options) x = _Base.get(self.bucket, id, expiration, **final_options) _Base.lock(self.bucket, id, options) return ResultPrecursor(x, options)
def _get_generic(self, key, kwargs, options): options = forward_args(kwargs, *options) options.pop('key', None) spec = options.pop('spec', []) project = options.pop('project', None) if project: if len(project) <= CBCollection.MAX_GET_OPS: spec = gen_projection_spec(project) else: raise couchbase.exceptions.ArgumentError( "Project only accepts {} operations or less".format(CBCollection.MAX_GET_OPS)) if not project: x = _Base.get(self.bucket, key, **options) else: x = self.bucket.lookup_in(key, *spec, **options) return ResultPrecursor(x, options)
def get(self, # type: Bucket key, # type: str ttl=0, # type: int quiet=None, # type: bool replica=False, # type: bool no_format=False # type: bool ): # type: (...) -> couchbase_v2.result.Result """Obtain an object stored in Couchbase by given key. :param string key: The key to fetch. The type of key is the same as mentioned in :meth:`upsert` :param int ttl: If specified, indicates that the key's expiry time should be *modified* when retrieving the value. :param boolean quiet: causes `get` to return None instead of raising an exception when the key is not found. It defaults to the value set by :attr:`~quiet` on the instance. In `quiet` mode, the error may still be obtained by inspecting the :attr:`~.Result.rc` attribute of the :class:`.Result` object, or checking :attr:`.Result.success`. Note that the default value is `None`, which means to use the :attr:`quiet`. If it is a boolean (i.e. `True` or `False`) it will override the `couchbase_v2.bucket.Bucket`-level :attr:`quiet` attribute. :param bool replica: Whether to fetch this key from a replica rather than querying the master server. This is primarily useful when operations with the master fail (possibly due to a configuration change). It should normally be used in an exception handler like so Using the ``replica`` option:: try: res = c.get("key", quiet=True) # suppress not-found errors catch CouchbaseException: res = c.get("key", replica=True, quiet=True) :param bool no_format: If set to ``True``, then the value will always be delivered in the :class:`~couchbase_v2.result.Result` object as being of :data:`~couchbase_v2.FMT_BYTES`. This is a item-local equivalent of using the :attr:`data_passthrough` option :raise: :exc:`.DocumentNotFoundException` if the key does not exist :raise: :exc:`.CouchbaseNetworkException` :raise: :exc:`.ValueFormatException` if the value cannot be deserialized with chosen decoder, e.g. if you try to retreive an object stored with an unrecognized format :return: A :class:`~.Result` object Simple get:: value = cb.get('key').value Get multiple values:: cb.get_multi(['foo', 'bar']) # { 'foo' : <Result(...)>, 'bar' : <Result(...)> } Inspect the flags:: rv = cb.get("key") value, flags, cas = rv.value, rv.flags, rv.cas Update the expiry time:: rv = cb.get("key", ttl=10) # Expires in ten seconds .. seealso:: :meth:`get_multi` """ return _Base.get(self, key, ttl=ttl, quiet=quiet, replica=replica, no_format=no_format)