def get(self, key): """ Get the value of a key from etcd. example usage: .. code-block:: python >>> import etcd3 >>> etcd = etcd3.client() >>> etcd.get('/thing/key') 'hello world' :param key: key in etcd to get :returns: value of key and metadata :rtype: bytes, ``KVMetadata`` """ range_request = self._build_get_range_request(key) range_response = self.kvstub.Range(range_request, self.timeout) if range_response.count < 1: raise exceptions.KeyNotFoundError( 'the key "{}" was not found'.format(key)) else: kv = range_response.kvs.pop() return kv.value, KVMetadata(kv)
def get_range(self, start_key, end_key='\0'): range_request = etcdrpc.RangeRequest() range_request.key = start_key.encode('utf-8') range_request.range_end = end_key.encode('utf-8') range_response = self.kvstub.Range(range_request) if range_response.count < 1: raise exceptions.KeyNotFoundError('no keys found') else: for kv in range_response.kvs: yield (kv.key, kv.value)
def get(self, key): """ Get the value of a key from etcd. :param key: key in etcd to get :returns: value of key :rtype: bytes """ range_request = self._build_get_range_request(key) range_response = self.kvstub.Range(range_request) if range_response.count < 1: raise exceptions.KeyNotFoundError( 'the key "{}" was not found'.format(key)) else: # smells funny - there must be a cleaner way to get the value? return range_response.kvs.pop().value
def get(self, key): ''' Get the value of a key from etcd. :param key: key in etcd to get :returns: value of key :rtype: bytes ''' range_request = etcdrpc.RangeRequest() range_request.key = key.encode('utf-8') range_response = self.kvstub.Range(range_request) if range_response.count < 1: raise exceptions.KeyNotFoundError( 'the key "{}" was not found'.format(key)) else: # smells funny - there must be a cleaner way to get the value? return range_response.kvs.pop().value
def get_all(self, sort_order=None, sort_target='key'): """ Get all keys currently stored in etcd. :returns: sequence of (value, metadata) tuples """ range_request = self._build_get_range_request( key=b'\0', range_end=b'\0', sort_order=sort_order, sort_target=sort_target, ) range_response = self.kvstub.Range(range_request, self.timeout) if range_response.count < 1: raise exceptions.KeyNotFoundError('no keys') else: for kv in range_response.kvs: yield (kv.value, KVMetadata(kv))
def get_prefix(self, key_prefix, sort_order=None, sort_target='key'): """ Get a range of keys with a prefix. :param key_prefix: first key in range :returns: sequence of (value, metadata) tuples """ range_request = self._build_get_range_request( key=key_prefix, range_end=utils.increment_last_byte(utils.to_bytes(key_prefix)), sort_order=sort_order, ) range_response = self.kvstub.Range(range_request, self.timeout) if range_response.count < 1: raise exceptions.KeyNotFoundError('no keys found') else: for kv in range_response.kvs: yield (kv.value, KVMetadata(kv))