コード例 #1
0
    def get_index(self,
                  transport,
                  bucket,
                  index,
                  startkey,
                  endkey=None,
                  return_terms=None,
                  max_results=None,
                  continuation=None,
                  timeout=None,
                  term_regex=None):
        """
        get_index(bucket, index, startkey, endkey=None, return_terms=None,\
                  max_results=None, continuation=None, timeout=None,\
                  term_regex=None)

        Queries a secondary index, returning matching keys.

        .. note:: This request is automatically retried :attr:`retries`
           times if it fails due to network error.

        :param bucket: the bucket whose index will be queried
        :type bucket: RiakBucket
        :param index: the index to query
        :type index: string
        :param startkey: the sole key to query, or beginning of the query range
        :type startkey: string, integer
        :param endkey: the end of the query range (optional if equality)
        :type endkey: string, integer
        :param return_terms: whether to include the secondary index value
        :type return_terms: boolean
        :param max_results: the maximum number of results to return (page size)
        :type max_results: integer
        :param continuation: the opaque continuation returned from a
            previous paginated request
        :type continuation: string
        :param timeout: a timeout value in milliseconds, or 'infinity'
        :type timeout: int
        :param term_regex: a regular expression used to filter index terms
        :type term_regex: string
        :rtype: :class:`~riak.client.index_page.IndexPage`
        """
        _validate_timeout(timeout, infinity_ok=True)

        page = IndexPage(self, bucket, index, startkey, endkey, return_terms,
                         max_results, term_regex)

        results, continuation = transport.get_index(bucket,
                                                    index,
                                                    startkey,
                                                    endkey,
                                                    return_terms=return_terms,
                                                    max_results=max_results,
                                                    continuation=continuation,
                                                    timeout=timeout,
                                                    term_regex=term_regex)

        page.results = results
        page.continuation = continuation
        return page
コード例 #2
0
    def get_index(self, transport, bucket, index, startkey, endkey=None,
                  return_terms=None, max_results=None, continuation=None,
                  timeout=None, term_regex=None):
        """
        get_index(bucket, index, startkey, endkey=None, return_terms=None,\
                  max_results=None, continuation=None, timeout=None,\
                  term_regex=None)

        Queries a secondary index, returning matching keys.

        .. note:: This request is automatically retried :attr:`retries`
           times if it fails due to network error.

        :param bucket: the bucket whose index will be queried
        :type bucket: RiakBucket
        :param index: the index to query
        :type index: string
        :param startkey: the sole key to query, or beginning of the query range
        :type startkey: string, integer
        :param endkey: the end of the query range (optional if equality)
        :type endkey: string, integer
        :param return_terms: whether to include the secondary index value
        :type return_terms: boolean
        :param max_results: the maximum number of results to return (page size)
        :type max_results: integer
        :param continuation: the opaque continuation returned from a
            previous paginated request
        :type continuation: string
        :param timeout: a timeout value in milliseconds, or 'infinity'
        :type timeout: int
        :param term_regex: a regular expression used to filter index terms
        :type term_regex: string
        :rtype: :class:`~riak.client.index_page.IndexPage`
        """
        if timeout != 'infinity':
            _validate_timeout(timeout)

        page = IndexPage(self, bucket, index, startkey, endkey,
                         return_terms, max_results, term_regex)

        results, continuation = transport.get_index(
            bucket, index, startkey, endkey, return_terms=return_terms,
            max_results=max_results, continuation=continuation,
            timeout=timeout, term_regex=term_regex)

        page.results = results
        page.continuation = continuation
        return page
コード例 #3
0
    def stream_index(self, bucket, index, startkey, endkey=None,
                     return_terms=None, max_results=None, continuation=None,
                     timeout=None, term_regex=None):
        """
        Queries a secondary index, streaming matching keys through an
        iterator.

        The caller should explicitly close the returned iterator,
        either using :func:`contextlib.closing` or calling ``close()``
        explicitly. Consuming the entire iterator will also close the
        stream. If it does not, the associated connection might not be
        returned to the pool. Example::

            from contextlib import closing

            # Using contextlib.closing
            with closing(client.stream_index(mybucket, 'name_bin',
                                             'Smith')) as index:
                for key in index:
                    do_something(key)

            # Explicit close()
            stream = client.stream_index(mybucket, 'name_bin', 'Smith')
            for key in stream:
                 do_something(key)
            stream.close()

        :param bucket: the bucket whose index will be queried
        :type bucket: RiakBucket
        :param index: the index to query
        :type index: string
        :param startkey: the sole key to query, or beginning of the query range
        :type startkey: string, integer
        :param endkey: the end of the query range (optional if equality)
        :type endkey: string, integer
        :param return_terms: whether to include the secondary index value
        :type return_terms: boolean
        :param max_results: the maximum number of results to return (page size)
        :type max_results: integer
        :param continuation: the opaque continuation returned from a
            previous paginated request
        :type continuation: string
        :param timeout: a timeout value in milliseconds, or 'infinity'
        :type timeout: int
        :param term_regex: a regular expression used to filter index terms
        :type term_regex: string
        :rtype: :class:`~riak.client.index_page.IndexPage`

        """
        if timeout != 'infinity':
            _validate_timeout(timeout)

        page = IndexPage(self, bucket, index, startkey, endkey,
                         return_terms, max_results, term_regex)
        page.stream = True
        resource = self._acquire()
        transport = resource.object
        page.results = transport.stream_index(
            bucket, index, startkey, endkey, return_terms=return_terms,
            max_results=max_results, continuation=continuation,
            timeout=timeout, term_regex=term_regex)
        page.results.attach(resource)
        return page
コード例 #4
0
    def stream_index(self,
                     bucket,
                     index,
                     startkey,
                     endkey=None,
                     return_terms=None,
                     max_results=None,
                     continuation=None,
                     timeout=None,
                     term_regex=None):
        """
        Queries a secondary index, streaming matching keys through an
        iterator.

        The caller should explicitly close the returned iterator,
        either using :func:`contextlib.closing` or calling ``close()``
        explicitly. Consuming the entire iterator will also close the
        stream. If it does not, the associated connection might not be
        returned to the pool. Example::

            from contextlib import closing

            # Using contextlib.closing
            with closing(client.stream_index(mybucket, 'name_bin',
                                             'Smith')) as index:
                for key in index:
                    do_something(key)

            # Explicit close()
            stream = client.stream_index(mybucket, 'name_bin', 'Smith')
            for key in stream:
                 do_something(key)
            stream.close()

        :param bucket: the bucket whose index will be queried
        :type bucket: RiakBucket
        :param index: the index to query
        :type index: string
        :param startkey: the sole key to query, or beginning of the query range
        :type startkey: string, integer
        :param endkey: the end of the query range (optional if equality)
        :type endkey: string, integer
        :param return_terms: whether to include the secondary index value
        :type return_terms: boolean
        :param max_results: the maximum number of results to return (page size)
        :type max_results: integer
        :param continuation: the opaque continuation returned from a
            previous paginated request
        :type continuation: string
        :param timeout: a timeout value in milliseconds, or 'infinity'
        :type timeout: int
        :param term_regex: a regular expression used to filter index terms
        :type term_regex: string
        :rtype: :class:`~riak.client.index_page.IndexPage`

        """
        # TODO FUTURE: implement "retry on connection closed"
        # as in stream_mapred
        _validate_timeout(timeout, infinity_ok=True)

        page = IndexPage(self, bucket, index, startkey, endkey, return_terms,
                         max_results, term_regex)
        page.stream = True
        resource = self._acquire()
        transport = resource.object
        page.results = transport.stream_index(bucket,
                                              index,
                                              startkey,
                                              endkey,
                                              return_terms=return_terms,
                                              max_results=max_results,
                                              continuation=continuation,
                                              timeout=timeout,
                                              term_regex=term_regex)
        page.results.attach(resource)
        return page