def test_list_get_by_index_return_types(self, return_type, expected): ''' Without a return type this should return the value ''' operation = list_operations.list_get_by_index( self.test_bin, 2, return_type) result = get_list_result_from_operation( self.as_connection, self.test_key, operation, self.test_bin) assert result == expected
def test_get_by_index(self, index, expected): ''' Without a return type this should return the value ''' operation = list_operations.list_get_by_index( self.test_bin, index, aerospike.LIST_RETURN_VALUE) result = get_list_result_from_operation( self.as_connection, self.test_key, operation, self.test_bin) assert result == expected
def test_list_get_by_index_return_types(self, return_type, expected): ''' Without a return type this should return the value ''' operation = list_operations.list_get_by_index(self.test_bin, 2, return_type) result = get_list_result_from_operation(self.as_connection, self.test_key, operation, self.test_bin) assert result == expected
def test_get_by_index(self, index, expected): ''' Without a return type this should return the value ''' operation = list_operations.list_get_by_index( self.test_bin, index, aerospike.LIST_RETURN_VALUE) result = get_list_result_from_operation(self.as_connection, self.test_key, operation, self.test_bin) assert result == expected
key, metadata, bins = client.operate_ordered(key, ops) print("\nremove_by_index_range('l', -2, NONE)") print("append('l', [1, 3, 3, 7, 0])") print("{}".format(bins[1][1])) # remove_by_index_range('l', -2, NONE) # append('l', [1, 3, 3, 7, 0]) # [11, 10, [1, 3, 3, 7, 0]] # remove all but the last 2 elements from the list nested within the # last element of the outer list ctx = [cdt_ctx.cdt_ctx_list_index(-1)] ops = [ listops.list_remove_by_index_range( "l", -2, aerospike.LIST_RETURN_NONE, inverted=True, ctx=ctx ), listops.list_get_by_index("l", -1, aerospike.LIST_RETURN_VALUE), ] key, metadata, bins = client.operate_ordered(key, ops) print("\nremove_by_index_range('l', -2, INVERTED|NONE, BY_LIST_INDEX(-1))") print("Inner list after the operation: {}".format(bins[0][1])) # remove_by_index_range('l', -2, INVERTED|NONE, BY_LIST_INDEX(-1)) # Inner list after the operation: [7, 0] # try to perform a list operation on an index range outside of the current list try: key, metadata, bins = client.operate( key, [ listops.list_remove_by_index_range("l", 3, aerospike.LIST_RETURN_NONE), 2, operations.read("l"),
try: print("\nget_by_index(bin, index[, returnType, 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, 26, 11]}) key, metadata, bins = client.get(key) print("{}".format(bins["l"])) # put('l', [1, 4, 7, 3, 9, 26, 11]) # [1, 4, 7, 3, 9, 26, 11] # demonstrate the meaning of the different return types # for the list datatype read operations, by getting the element at index 1 # of the list multiple times in the same transaction ops = [ listops.list_get_by_index("l", 1, aerospike.LIST_RETURN_VALUE), listops.list_get_by_index("l", 1, aerospike.LIST_RETURN_INDEX), listops.list_get_by_index("l", 1, aerospike.LIST_RETURN_REVERSE_INDEX), listops.list_get_by_index("l", 1, aerospike.LIST_RETURN_RANK), listops.list_get_by_index("l", 1, aerospike.LIST_RETURN_REVERSE_RANK), listops.list_get_by_index("l", 1, aerospike.LIST_RETURN_COUNT), ] 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 print("\nget_by_index('l', 1, VALUE): {}".format(bins[0][1])) # get_by_index('l', 1, VALUE): 4 print("get_by_index('l', 1, INDEX): {}".format(bins[1][1])) # get_by_index('l', 1, INDEX): 1