def test_get_by_index_range_no_count(self):
        operation = list_operations.list_get_by_index_range(
            self.test_bin, 2, aerospike.LIST_RETURN_VALUE)

        result = get_list_result_from_operation(
            self.as_connection, self.test_key, operation, self.test_bin)
        assert result == self.test_list[2:]
    def test_get_by_index_range_no_count(self):
        operation = list_operations.list_get_by_index_range(
            self.test_bin, 2, aerospike.LIST_RETURN_VALUE)

        result = get_list_result_from_operation(self.as_connection,
                                                self.test_key, operation,
                                                self.test_bin)
        assert result == self.test_list[2:]
    def test_get_by_index_range_both_present(self, index, count):
        expected = self.test_list[index: index + count]
        operation = list_operations.list_get_by_index_range(
            self.test_bin, index, aerospike.LIST_RETURN_VALUE, count)

        result = get_list_result_from_operation(
            self.as_connection, self.test_key, operation, self.test_bin)
        assert result == expected
    def test_get_by_index_range_both_present(self, index, count):
        expected = self.test_list[index:index + count]
        operation = list_operations.list_get_by_index_range(
            self.test_bin, index, aerospike.LIST_RETURN_VALUE, count)

        result = get_list_result_from_operation(self.as_connection,
                                                self.test_key, operation,
                                                self.test_bin)
        assert result == expected
    def test_get_by_index_range_inverted(self):
        start = 0
        count = 3
        expected = self.test_list[start + count:]

        operation = list_operations.list_get_by_index_range(
            self.test_bin, start, aerospike.LIST_RETURN_VALUE, count=3,
            inverted=True)

        result = get_list_result_from_operation(
            self.as_connection, self.test_key, operation, self.test_bin)
        assert result == expected
    def test_get_by_index_range_inverted(self):
        start = 0
        count = 3
        expected = self.test_list[start + count:]

        operation = list_operations.list_get_by_index_range(
            self.test_bin,
            start,
            aerospike.LIST_RETURN_VALUE,
            count=3,
            inverted=True)

        result = get_list_result_from_operation(self.as_connection,
                                                self.test_key, operation,
                                                self.test_bin)
        assert result == expected
示例#7
0
    pass

try:
    print("\nget_by_index_range(bin, index[, returnType, count, context])\n")
    # create a new record with a put. list policy can't be applied outside of
    # list operations, and a new list is unordered by default
    client.put(key, {"l": [1, 4, 7, 3, 9, 9, 26, 11]})
    key, metadata, bins = client.get(key)
    print("{}".format(bins["l"]))
    # [1, 4, 7, 3, 9, 9, 26, 11]

    # demonstrate the meaning of the different return types
    # for the list data type read operations, by getting all the elements
    # starting at index 3 multiple times in the same transaction
    ops = [
        listops.list_get_by_index_range("l", 3, aerospike.LIST_RETURN_VALUE,
                                        3),
        listops.list_get_by_index_range("l", 3, aerospike.LIST_RETURN_INDEX,
                                        3),
        listops.list_get_by_index_range("l", 3,
                                        aerospike.LIST_RETURN_REVERSE_INDEX,
                                        3),
        listops.list_get_by_index_range("l", 3, aerospike.LIST_RETURN_RANK, 3),
        listops.list_get_by_index_range("l", 3,
                                        aerospike.LIST_RETURN_REVERSE_RANK, 3),
        listops.list_get_by_index_range("l", 3, aerospike.LIST_RETURN_COUNT,
                                        3),
    ]
    key, metadata, bins = client.operate_ordered(key, ops)
    # in the python client the operate() command returns the result of the last
    # operation on a specific bin, so using operate_ordered instead, which
    # gives the results as ordered (bin-name, result) tuples