aerospike_helpers.operations package
aerospike_helpers.operations.operations module
Module with helper functions to create dictionaries used by:
aerospike.Client.operate
andaerospike.Client.operate_ordered
Certain batch operations listed in
aerospike_helpers.batch.records
- aerospike_helpers.operations.operations.append(bin_name, append_item)
Create an append operation dictionary.
The append operation appends append_item to the value in bin_name.
- Parameters:
bin_name (str) – The name of the bin to be used.
append_item – The value which will be appended to the item contained in the specified bin.
- Returns:
A dictionary to be passed to operate or operate_ordered.
- aerospike_helpers.operations.operations.delete()
Create a delete operation dictionary.
The delete operation deletes a record and all associated bins. Requires server version >= 4.7.0.8.
- Returns:
A dictionary to be passed to operate or operate_ordered.
- aerospike_helpers.operations.operations.increment(bin_name, amount)
Create an increment operation dictionary.
The increment operation increases a value in bin_name by the specified amount, or creates a bin with the value of amount.
- Parameters:
bin_name (str) – The name of the bin to be incremented.
amount – The amount by which to increment the item in the specified bin.
- Returns:
A dictionary to be passed to operate or operate_ordered.
- aerospike_helpers.operations.operations.prepend(bin_name, prepend_item)
Create a prepend operation dictionary.
The prepend operation prepends prepend_item to the value in bin_name.
- Parameters:
bin_name (str) – The name of the bin to be used.
prepend_item – The value which will be prepended to the item contained in the specified bin.
- Returns:
A dictionary to be passed to operate or operate_ordered.
- aerospike_helpers.operations.operations.read(bin_name)
Create a read operation dictionary.
The read operation reads and returns the value in bin_name.
- Parameters:
bin_name (str) – the name of the bin from which to read.
- Returns:
A dictionary to be passed to operate or operate_ordered.
- aerospike_helpers.operations.operations.touch(ttl: int | None = None)
Create a touch operation dictionary.
Using ttl here is deprecated. It should be set in the record metadata for the operate method.
- Parameters:
ttl (int) – Deprecated. The ttl that should be set for the record. This should be set in the metadata passed to the operate or operate_ordered methods.
- Returns:
A dictionary to be passed to operate or operate_ordered.
- aerospike_helpers.operations.operations.write(bin_name, write_item)
Create a write operation dictionary.
The write operation writes write_item into the bin specified by bin_name.
- Parameters:
bin_name (str) – The name of the bin into which write_item will be stored.
write_item – The value which will be written into the bin.
- Returns:
A dictionary to be passed to operate or operate_ordered.
aerospike_helpers.operations.list_operations module
This module provides helper functions to produce dictionaries to be used with:
aerospike.Client.operate
andaerospike.Client.operate_ordered
Certain batch operations listed in
aerospike_helpers.batch.records
List operations support nested CDTs through an optional ctx context argument.
The ctx argument is a list of cdt_ctx context operation objects. See aerospike_helpers.cdt_ctx
.
For list operations that take in an index parameter, you can use negative values for indexes. See this page.
Note
Nested CDT (ctx) requires server version >= 4.6.0
- aerospike_helpers.operations.list_operations.list_append(bin_name: str, value, policy: dict | None = None, ctx: list | None = None)
Creates a list append operation.
The list append operation instructs the aerospike server to append an item to the end of a list bin.
Returns a dictionary that maps the bin name to the list size after appending the item.
- Parameters:
bin_name (str) – The name of the bin to be operated on.
value – The value to be appended to the end of the list.
policy (dict) – An optional dictionary of list write options.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_append_items(bin_name: str, values, policy: dict | None = None, ctx: list | None = None)
Creates a list append items operation.
The list append items operation instructs the aerospike server to append multiple items to the end of a list bin.
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_clear(bin_name: str, ctx: list | None = None)
Create list clear operation.
The list clear operation removes all items from the list specified by bin_name
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_create(bin_name: str, list_order: int, pad: bool, persist_index: bool, ctx: list | None = None)
Create list create operation.
Server creates list at given context level.
- Parameters:
bin_name (str) – Bin name.
list_order (int) – See List Order for possible values.
persist_index (bool) – If
True
, persist list index. A list index improves lookup performance, but requires more storage. A list index can be created for a top-level ordered list only. Nested and unordered list indexes are not supported.ctx (Optional[dict]) – An optional list of nested CDT
cdt_ctx
specifying the path to nested list. If not defined, the top-level list is used.
- aerospike_helpers.operations.list_operations.list_get(bin_name: str, index, ctx: list | None = None)
Create a list get operation.
The list get operation gets the value of the item at index and returns the value
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_get_by_index(bin_name: str, index, return_type, ctx: list | None = None)
Create a list get index operation.
The list get operation gets the item at index and returns a value specified by return_type
- Parameters:
bin_name (str) – The name of the bin containing the list to fetch items from.
index (int) – The index of the item to be returned.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_get_by_index_range(bin_name: str, index, return_type, count=None, inverted=False, ctx: list | None = None)
Create a list get index range operation.
The list get by index range operation gets count items starting at index and returns a value specified by return_type
- Parameters:
bin_name (str) – The name of the bin containing the list to fetch items from.
index (int) – The index of the first item to be returned.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.
count (int) – The number of list items to be selected.
inverted (bool) – Optional bool specifying whether to invert the return type. If set to True, all items outside of the specified range will be returned. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_get_by_rank(bin_name: str, rank, return_type, ctx: list | None = None)
Create a list get by rank operation.
Server selects list item identified by rank and returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list to fetch a value from.
rank (int) – The rank of the item to be fetched.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_get_by_rank_range(bin_name: str, rank, return_type, count=None, inverted=False, ctx: list | None = None)
Create a list get by rank range operation.
Server selects count items starting at the specified rank and returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list to fetch items from.
rank (int) – The rank of the first items to be returned.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
count (int) – A positive number indicating number of items to be returned.
inverted (bool) – Optional bool specifying whether to invert the return type. If set to True, all items outside of the specified rank range will be returned. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_get_by_value(bin_name: str, value, return_type, inverted=False, ctx: list | None = None)
Create a list get by value operation.
Server selects list items with a value equal to value and returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list to fetch items from.
value – The server returns all items matching this value
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
inverted (bool) – Optional bool specifying whether to invert the return type. If set to True, all items not equal to value will be selected. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_get_by_value_list(bin_name: str, value_list, return_type, inverted=False, ctx: list | None = None)
Create a list get by value list operation.
Server selects list items with a value contained in value_list and returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list to fetch items from.
value_list (list) – Return items from the list matching an item in this list.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
inverted (bool) – Optional bool specifying whether to invert the return type. If set to True, all items not matching an entry in value_list will be selected. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_get_by_value_range(bin_name: str, return_type, value_begin, value_end, inverted=False, ctx: list | None = None)
Create a list get by value list operation.
Server selects list items with a value greater than or equal to value_begin and less than value_end. If value_begin is None, range is greater than or equal to the first element of the list. If value_end is None range extends to the end of the list. Server returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list to fetch items from.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
value_begin – The start of the value range.
value_end – The end of the value range.
inverted (bool) – Optional bool specifying whether to invert the return type. If set to True, all items not included in the specified range will be returned. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_get_by_value_rank_range_relative(bin_name: str, value, offset, return_type, count=None, inverted=False, ctx: list | None = None)
Create a list get by value rank range relative operation
Create list get by value relative to rank range operation. Server selects list items nearest to value and greater by relative rank. Server returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list.
value (str) – The value of the item in the list for which to search
offset (int) – Begin returning items with rank == rank(found_item) + offset
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
count (int) – If specified, the number of items to return. If None, all items until end of list are returned.
inverted (bool) – If True, the operation is inverted, and items outside of the specified range are returned.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
.The format of the dictionary should be considered an internal detail, and subject to change.
Note
This operation requires server version 4.3.0 or greater.
Examples
These examples show what would be returned for specific arguments when dealing with an ordered list:
[0,4,5,9,11,15]
(value, offset, count) = [selected items] # Found 5 # Rank 0 = 5 # No upper limit, so get all elements >= 5 (5, 0, None) = [5,9,11,15] # Only get 2 elements (5, 0, 2) = [5, 9] # Relative rank -1 = 4 # since 4 is just below 5 in the list # Then get all elements >= 4 (5, -1, None) = [4, 5, 9, 11, 15] # Only get 3 elements (5, -1, 3) = [4, 5, 9] # 3 not in list # But next greater value is 4, so set 4's rank to 0 # Then rank 0 = 4, rank 1 = 5, rank 2 = 9, rank 3 = 11 (3,3, None) = [11, 15] # Rank 0 = 4, Rank -1 = 0 # We will only get down to the lowest rank item (3,-3, None) = [0, 4,5,9,11,15] (3, 0, None) = [4,5,9,11,15]
- aerospike_helpers.operations.list_operations.list_get_range(bin_name: str, index, count, ctx: list | None = None)
Create a list get range operation.
The list get range operation gets count items starting index and returns the values.
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_increment(bin_name: str, index, value, policy: dict | None = None, ctx: list | None = None)
Creates a list increment operation.
The list increment operation increments an item at index: index in the list contained in the specified bin.
- Parameters:
bin_name (str) – The name of the bin to be operated on.
index (int) – The index of the list item to increment.
value (int, float) – The value to be added to the list item.
policy (dict) – An optional dictionary of list write options.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_insert(bin_name: str, index, value, policy: dict | None = None, ctx: list | None = None)
Creates a list insert operation.
The list insert operation inserts an item at index: index into the list contained in the specified bin.
- Parameters:
bin_name (str) – The name of the bin to be operated on.
index (int) – The index at which to insert an item. The value may be positive to use zero based indexing or negative to index from the end of the list.
value – The value to be inserted into the list.
policy (dict) – An optional dictionary of list write options.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_insert_items(bin_name: str, index, values, policy: dict | None = None, ctx: list | None = None)
Creates a list insert items operation.
The list insert items operation inserts items at index: index into the list contained in the specified bin. Server returns list size.
- Parameters:
bin_name (str) – The name of the bin to be operated on.
index (int) – The index at which to insert the items. The value may be positive to use zero based indexing or negative to index from the end of the list.
values (list) – The values to be inserted into the list.
policy (dict) – An optional dictionary of list write options.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_pop(bin_name: str, index, ctx: list | None = None)
Creates a list pop operation.
The list pop operation removes and returns an item index: index from list contained in the specified bin.
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_pop_range(bin_name: str, index, count, ctx: list | None = None)
Creates a list pop range operation.
The list pop range operation removes and returns count items starting from index: index from the list contained in the specified bin.
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_remove(bin_name: str, index, ctx: list | None = None)
Creates a list remove operation.
The list remove operation removes an item located at index in the list specified by bin_name. Server returns number of items removed.
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_remove_by_index(bin_name: str, index, return_type, ctx: list | None = None)
Create a list remove by index operation.
The list_remove_by_index operation removes the value of the item at index and returns a value specified by return_type
- Parameters:
bin_name (str) – The name of the bin containing the list to remove an item from.
index (int) – The index of the item to be removed.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_remove_by_index_range(bin_name: str, index, return_type, count=None, inverted=False, ctx: list | None = None)
Create a list remove by index range operation.
The list remove by index range operation removes count starting at index and returns a value specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list to remove items from.
index (int) – The index of the first item to be removed.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values.
count (int) – The number of items to be removed
inverted (bool) – Optional bool specifying whether to invert the operation. If set to True, all items outside of the specified range will be removed. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_remove_by_rank(bin_name: str, rank, return_type, ctx: list | None = None)
Create a list remove by rank operation.
Server removes a list item identified by rank and returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list to fetch a value from.
rank (int) – The rank of the item to be removed.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_remove_by_rank_range(bin_name: str, rank, return_type, count=None, inverted=False, ctx: list | None = None)
Create a list remove by rank range operation.
Server removes count items starting at the specified rank and returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list to fetch items from.
rank (int) – The rank of the first item to removed.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
count (int) – A positive number indicating number of items to be removed.
inverted (bool) – Optional bool specifying whether to invert the operation. If set to True, all items outside of the specified rank range will be removed. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_remove_by_value(bin_name: str, value, return_type, inverted=False, ctx: list | None = None)
Create a list remove by value operation.
Server removes list items with a value equal to value and returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list to remove items from.
value – The server removes all list items matching this value.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
inverted (bool) – Optional bool specifying whether to invert the operation. If set to True, all items not equal to value will be removed. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
.The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_remove_by_value_list(bin_name: str, value_list, return_type, inverted=False, ctx: list | None = None)
Create a list remove by value list operation.
Server removes list items with a value matching one contained in value_list and returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list to remove items from.
value_list (list) – The server removes all list items matching one of these values.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
inverted (bool) – Optional bool specifying whether to invert the operation. If set to True, all items not equal to a value contained in value_list will be removed. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_remove_by_value_range(bin_name: str, return_type, value_begin=None, value_end=None, inverted=False, ctx: list | None = None)
Create a list remove by value range operation.
Server removes list items with a value greater than or equal to value_begin and less than value_end. If value_begin is None, range is greater than or equal to the first element of the list. If value_end is None range extends to the end of the list. Server returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list to fetch items from.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
value_begin – The start of the value range.
value_end – The end of the value range.
inverted (bool) – Optional bool specifying whether to invert the operation. If set to True, all items not included in the specified range will be removed. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
.The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_remove_by_value_rank_range_relative(bin_name: str, value, offset, return_type, count=None, inverted=False, ctx: list | None = None)
Create a list get by value rank range relative operation
Create list remove by value relative to rank range operation. Server removes and returns list items nearest to value and greater by relative rank. Server returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list.
value (str) – The value of the item in the list for which to search
offset (int) – Begin removing and returning items with rank == rank(found_item) + offset
return_type (int) – Value specifying what should be returned from the operation. This should be one of the List Return Types values
count (int) – If specified, the number of items to remove and return. If None, all items until end of list are returned.
inverted (bool) – If True, the operation is inverted, and items outside of the specified range are removed and returned.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
.The format of the dictionary should be considered an internal detail, and subject to change.
Note
This operation requires server version 4.3.0 or greater.
These examples show what would be removed and returned for specific arguments when dealing with an ordered list:
[0,4,5,9,11,15]
(value, offset, count) = [selected items] (5,0,None) = [5,9,11,15] (5,0,2) = [5, 9] (5,-1, None) = [4,5,9,11,15] (5, -1, 3) = [4,5,9] (3,3, None) = [11,15] # We can only go down to lowest rank item (3,-3, None) = [0,4,5,9,11,15] (3, 0, None) = [4,5,9,11,15]
- aerospike_helpers.operations.list_operations.list_remove_range(bin_name: str, index, count, ctx: list | None = None)
Creates a list remove range operation.
The list remove range operation removes count items starting at index in the list specified by bin_name. Server returns number of items removed.
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_set(bin_name: str, index, value, policy: dict | None = None, ctx: list | None = None)
Create a list set operation.
The list set operations sets the value of the item at index to value. Server does not return a result by default.
- Parameters:
bin_name (str) – The name of the bin containing the list to be operated on.
index (int) – The index of the item to be set.
value – The value to be assigned to the list item.
policy (dict) – An optional dictionary of list write options.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_set_order(bin_name: str, list_order, ctx: list | None = None)
Create a list set order operation.
The list_set_order operation sets an order on a specified list bin.
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
.The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_size(bin_name: str, ctx: list | None = None)
Create a list size operation.
Server returns the size of the list in the specified bin.
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_sort(bin_name: str, sort_flags: int = 0, ctx: list | None = None)
Create a list sort operation
The list sort operation will sort the specified list bin.
- Parameters:
bin_name (str) – The name of the bin to sort.
sort_flags (int) – List Sort Flags modifying the sorting behavior (default
aerospike.DEFAULT_LIST_SORT
).ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
.The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.list_operations.list_trim(bin_name: str, index, count, ctx: list | None = None)
Create a list trim operation.
Server removes items in list bin that do not fall into range specified by index and count range.
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
aerospike_helpers.operations.map_operations module
Helper functions to create map operation dictionaries arguments for:
aerospike.Client.operate
andaerospike.Client.operate_ordered
Certain batch operations listed in
aerospike_helpers.batch.records
Map operations support nested CDTs through an optional ctx context argument.
The ctx argument is a list of cdt_ctx context operation objects. See aerospike_helpers.cdt_ctx
.
For the map operations that remove map items, such as map_clear
and
all the remove_*
operations, if all map items are removed in a map, the map becomes empty (i.e it does not get
deleted).
Note
Nested CDT (ctx) requires server version >= 4.6.0
- aerospike_helpers.operations.map_operations.map_clear(bin_name: str, ctx: list | None = None)
Creates a map_clear operation.
The operation removes all items from the map stored in the specified bin.
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_create(bin_name: str, map_order: int, persist_index: bool, ctx: list | None = None)
Create map create operation.
Server creates map at given context level.
- Parameters:
bin_name (str) – Bin name.
persist_index (bool) – If
True
, persist map index. A map index improves lookup performance, but requires more storage. A map index can be created for a top-level ordered map only. Nested and unordered map indexes are not supported.ctx (Optional[dict]) – An optional list of nested CDT
cdt_ctx
specifying the path to nested map. If not defined, the top-level map is used.
- aerospike_helpers.operations.map_operations.map_decrement(bin_name: str, key, amount, map_policy: dict | None = None, ctx: list | None = None)
Creates a map_decrement operation.
The operation allows a user to decrement the value of a value stored in the map on the server.
- Parameters:
bin_name (str) – The name of the bin containing the map.
key – The key for the value to be decremented.
amount – The amount by which to decrement the value stored in map[key]
map_policy (dict) – Optional map_policy dictionary specifies the mode of writing items to the Map, and dictates the map order if there is no Map at the bin_name.
"persist_index"
option is also applied.ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_get_by_index(bin_name: str, index, return_type, ctx: list | None = None)
Creates a map_get_by_index operation.
The operation returns the entry at index from the map.
- Parameters:
bin_name (str) – The name of the bin containing the map.
index (int) – The index of the entry to return.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_get_by_index_range(bin_name: str, index_start, get_amt, return_type, inverted=False, ctx: list | None = None)
Creates a map_get_by_index_range operation.
The operation returns get_amt entries starting at index_start from the map.
- Parameters:
bin_name (str) – The name of the bin containing the map.
index_start (int) – The index of the first entry to return.
get_amt (int) – The number of entries to return from the map.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If true, entries in the specified index range should be ignored, and all other entries returned. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_get_by_key(bin_name: str, key, return_type, ctx: list | None = None)
Creates a map_get_by_key operation.
The operation returns an item, specified by the key from the map stored in the specified bin.
- Parameters:
bin_name (str) – The name of the bin containing the map.
key – The key of the item to be returned from the map
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_get_by_key_index_range_relative(bin_name: str, value, offset, return_type, count=None, inverted=False, ctx: list | None = None)
Create a map get by value rank range relative operation
Create map get by key relative to index range operation. Server removes and returns map items with key nearest to value and greater by relative index. Server returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the list.
value (str) – The value of the item in the list for which to search
offset (int) – Begin removing and returning items with rank == rank(fount_item) + offset
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
count (int) – If specified, the number of items to remove and return. If None, all items until end of list are returned.
inverted (bool) – If True, the operation is inverted and items outside of the specified range are returned.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in operate or operate_ordered.The format of the dictionary should be considered an internal detail, and subject to change.
Note
This operation requires server version 4.3.0 or greater.
Examples for a key ordered map
{0: 6, 6: 12, 10: 18, 15: 24}
and return type ofaerospike.MAP_RETURN_KEY
. Seemap_remove_by_key_index_range_relative()
for in-depth explanation.(value, offset, count) = [returned keys] (5, 0, None) = [6, 10, 15] (5, 0, 2) = [6, 10] (5,-1, None) = [0, 6, 10, 15] (5, -1, 3) = [0, 6, 10] (3, 2, None) = [15] (3, 5, None) = []
- aerospike_helpers.operations.map_operations.map_get_by_key_list(bin_name: str, key_list, return_type, inverted=False, ctx: list | None = None)
Creates a map_get_by_key_list operation.
The operation returns items, specified by the keys in key_list from the map stored in the specified bin.
- Parameters:
bin_name (str) – The name of the bin containing the map.
key_list (list) – A list of keys to be returned from the map.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If true, keys with values not specified in the key_list will be returned, and those keys specified in the key_list will be ignored. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_get_by_key_range(bin_name: str, key_range_start, key_range_end, return_type, inverted=False, ctx: list | None = None)
Creates a map_get_by_key_range operation.
The operation returns items with keys between key_range_start(inclusive) and key_range_end(exclusive) from the map
- Parameters:
bin_name (str) – The name of the bin containing the map.
key_range_start – The start of the range of keys to be returned. (Inclusive)
key_range_end – The end of the range of keys to be returned. (Exclusive)
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If True, values outside of the specified range will be returned, and values inside of the range will be ignored. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_get_by_rank(bin_name: str, rank, return_type, ctx: list | None = None)
Creates a map_get_by_rank operation.
The operation returns the item with the specified rank from the map.
- Parameters:
bin_name (str) – The name of the bin containing the map.
rank (int) – The rank of the entry to return.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_get_by_rank_range(bin_name: str, rank_start, get_amt, return_type, inverted=False, ctx: list | None = None)
Creates a map_get_by_rank_range operation.
The operation returns item within the specified rank range from the map.
- Parameters:
bin_name (str) – The name of the bin containing the map.
rank_start (int) – The start of the rank of the entries to return.
get_amt (int) – The number of entries to return.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If True, items with ranks inside the specified range should be ignored, and all other entries returned. Default: False.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_get_by_value(bin_name: str, value, return_type, inverted=False, ctx: list | None = None)
Creates a map_get_by_value operation.
The operation returns entries whose value matches the specified value.
- Parameters:
bin_name (str) – The name of the bin containing the map.
value – Entries with a value matching this argument will be returned from the map.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If True, entries with a value different than the specified value will be returned. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_get_by_value_list(bin_name: str, key_list, return_type, inverted=False, ctx: list | None = None)
Creates a map_get_by_value_list operation.
The operation returns entries whose values are specified in the value_list.
- Parameters:
bin_name (str) – The name of the bin containing the map.
key_list (list) – Entries with a value contained in this list will be returned from the map.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If True, entries with a value contained in value_list will be ignored, and all others will be returned.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_get_by_value_range(bin_name: str, value_start, value_end, return_type, inverted=False, ctx: list | None = None)
Creates a map_get_by_value_range operation.
The operation returns items, with values between value_start(inclusive) and value_end(exclusive) from the map
- Parameters:
bin_name (str) – The name of the bin containing the map.
value_start – The start of the range of values to be returned. (Inclusive)
value_end – The end of the range of values to be returned. (Exclusive)
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If True, values outside of the specified range will be returned, and values inside of the range will be ignored. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_get_by_value_rank_range_relative(bin_name: str, value, offset, return_type, count=None, inverted=False, ctx: list | None = None)
Create a map remove by value rank range relative operation
Create list map get by value relative to rank range operation. Server returns map items with value nearest to value and greater by relative rank. Server returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the map.
value (str) – The value of the item in the list for which to search
offset (int) – Begin removing and returning items with rank == rank(fount_item) + offset
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
count (int) – If specified, the number of items to remove and return. If None, all items until end of list are returned.
inverted (bool) – If True, the operation is inverted and items outside of the specified range are returned.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in operate or operate_ordered.The format of the dictionary should be considered an internal detail, and subject to change.
Note
This operation requires server version 4.3.0 or greater.
Examples for map
{0: 6, 10: 18, 6: 12, 15: 24}
and return type ofaerospike.MAP_RETURN_KEY
. Seemap_remove_by_value_rank_range_relative()
for in-depth explanation.(value, offset, count) = [returned keys] (6, 0, None) = [0, 6, 10, 15] (5, 0, 2) = [0, 6] (7, -1, 1) = [0] (7, -1, 3) = [0, 6, 10]
- aerospike_helpers.operations.map_operations.map_increment(bin_name: str, key, amount, map_policy: dict | None = None, ctx: list | None = None)
Creates a map_increment operation.
The operation allows a user to increment the value of a value stored in the map on the server.
- Parameters:
bin_name (str) – The name of the bin containing the map.
key – The key for the value to be incremented.
amount – The amount by which to increment the value stored in map[key]
map_policy (dict) – Optional map_policy dictionary specifies the mode of writing items to the Map, and dictates the map order if there is no Map at the bin_name.
"persist_index"
option is also applied.ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_put(bin_name: str, key, value, map_policy: dict | None = None, ctx: list | None = None)
Creates a map_put operation.
The operation allows a user to set the value of an item in the map stored on the server.
- Parameters:
bin_name (str) – The name of the bin containing the map.
key – The key for the map.
value – The item to store in the map with the corresponding key.
map_policy (dict) – Optional map_policy dictionary specifies the mode of writing items to the Map, and dictates the map order if there is no Map at the bin_name.
"persist_index"
option is also applied.ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_put_items(bin_name: str, item_dict, map_policy: dict | None = None, ctx: list | None = None)
Creates a map_put_items operation.
The operation allows a user to add or update items in the map stored on the server.
- Parameters:
bin_name (str) – The name of the bin containing the map.
item_dict (dict) – A dictionary of key value pairs to be added to the map on the server.
map_policy (dict) – Optional map_policy dictionary specifies the mode of writing items to the Map, and dictates the map order if there is no Map at the bin_name.
"persist_index"
option is also applied.ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_remove_by_index(bin_name: str, index, return_type, ctx: list | None = None)
Creates a map_remove_by_index operation.
The operation removes the entry at index from the map.
- Parameters:
bin_name (str) – The name of the bin containing the map.
index (int) – The index of the entry to remove.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_remove_by_index_range(bin_name: str, index_start, remove_amt, return_type, inverted=False, ctx: list | None = None)
Creates a map_remove_by_index_range operation.
The operation removes remove_amt entries starting at index_start from the map.
- Parameters:
bin_name (str) – The name of the bin containing the map.
index_start (int) – The index of the first entry to remove.
remove_amt (int) – The number of entries to remove from the map.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If true, entries in the specified index range should be kept, and all other entries removed. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_remove_by_key(bin_name: str, key, return_type, ctx: list | None = None)
Creates a map_remove_by_key operation.
The operation removes an item, specified by the key from the map stored in the specified bin.
- Parameters:
bin_name (str) – The name of the bin containing the map.
key – The key to be removed from the map
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_remove_by_key_index_range_relative(bin_name: str, key, offset, return_type, count=None, inverted=False, ctx: list | None = None)
Create a map get by value rank range relative operation
Create map remove by key relative to index range operation. Server removes and returns map items with key nearest to value and greater by relative index. Server returns selected data specified by return_type.
Note
This operation requires server version 4.3.0 or greater.
- Parameters:
bin_name (str) – The name of the bin containing the list.
key (str) – The key of the item in the list for which to search
offset (int) – Begin removing and returning items with rank == rank(fount_item) + offset
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
count (int) – If specified, the number of items to remove and return. If None, all items until end of list are returned.
inverted (bool) – If True, the operation is inverted and items outside of the specified range are returned.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in operate or operate_ordered.The format of the dictionary should be considered an internal detail, and subject to change.
Examples for a key ordered map
{0: 6, 6: 12, 10: 18, 15: 24}
and return type ofaerospike.MAP_RETURN_KEY
(value, offset, count) = [removed keys] # Next greatest key is 6 # Rank 0 = 6 (5, 0, None) = [6, 10, 15] # Only delete 2 keys (5, 0, 2) = [6, 10] # Rank 0 = 6 # Rank -1 = 0 # Delete elements starting from key 0 (5,-1, None) = [0, 6, 10, 15] (5, -1, 3) = [0, 6, 10] # Rank 0 = 6, rank 1 = 10, rank 2 = 15 (3, 2, None) = [15] # No items with relative rank higher than 2 (3, 5, None) = []
- aerospike_helpers.operations.map_operations.map_remove_by_key_list(bin_name: str, key_list, return_type, inverted=False, ctx: list | None = None)
Creates a map_remove_by_key operation.
The operation removes items, specified by the keys in key_list from the map stored in the specified bin.
- Parameters:
bin_name (str) – The name of the bin containing the map.
key_list (list) – A list of keys to be removed from the map.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If true, keys with values not specified in the key_list will be removed, and those keys specified in the key_list will be kept. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_remove_by_key_range(bin_name: str, key_range_start, key_range_end, return_type, inverted=False, ctx: list | None = None)
Creates a map_remove_by_key_range operation.
The operation removes items, with keys between key_range_start(inclusive) and key_range_end(exclusive) from the map.
- Parameters:
bin_name (str) – The name of the bin containing the map.
key_range_start – The start of the range of keys to be removed. (Inclusive)
key_range_end – The end of the range of keys to be removed. (Exclusive)
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If True, values outside of the specified range will be removed, and values inside of the range will be kept. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_remove_by_rank(bin_name: str, rank, return_type, ctx: list | None = None)
Creates a map_remove_by_rank operation.
The operation removes the item with the specified rank from the map.
- Parameters:
bin_name (str) – The name of the bin containing the map.
rank (int) – The rank of the entry to remove.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_remove_by_rank_range(bin_name: str, rank_start, remove_amt, return_type, inverted=False, ctx: list | None = None)
Creates a map_remove_by_rank_range operation.
The operation removes remove_amt items beginning with the item with the specified rank from the map.
- Parameters:
bin_name (str) – The name of the bin containing the map.
rank_start (int) – The rank of the entry to remove.
remove_amt (int) – The number of entries to remove.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If True, items with ranks inside the specified range should be kept, and all other entries removed. Default: False.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_remove_by_value(bin_name: str, value, return_type, inverted=False, ctx: list | None = None)
Creates a map_remove_by_value operation.
The operation removes key value pairs whose value matches the specified value.
- Parameters:
bin_name (str) – The name of the bin containing the map.
value – Entries with a value matching this argument will be removed from the map.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If True, entries with a value different than the specified value will be removed. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_remove_by_value_list(bin_name: str, value_list, return_type, inverted=False, ctx: list | None = None)
Creates a map_remove_by_value_list operation.
The operation removes key value pairs whose values are specified in the value_list.
- Parameters:
bin_name (str) – The name of the bin containing the map.
value_list (list) – Entries with a value contained in this list will be removed from the map.
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If True, entries with a value contained in value_list will be kept, and all others will be removed and returned.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_remove_by_value_range(bin_name: str, value_start, value_end, return_type, inverted=False, ctx: list | None = None)
Creates a map_remove_by_value_range operation.
The operation removes items, with values between value_start(inclusive) and value_end(exclusive) from the map
- Parameters:
bin_name (str) – The name of the bin containing the map.
value_start – The start of the range of values to be removed. (Inclusive)
value_end – The end of the range of values to be removed. (Exclusive)
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
inverted (bool) – If True, values outside of the specified range will be removed, and values inside of the range will be kept. Default: False
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_remove_by_value_rank_range_relative(bin_name: str, value, offset, return_type, count=None, inverted=False, ctx: list | None = None)
Create a map remove by value rank range relative operation
Create map remove by value relative to rank range operation. Server removes and returns map items nearest to value and greater by relative rank. Server returns selected data specified by return_type.
- Parameters:
bin_name (str) – The name of the bin containing the map.
value – The value of the entry in the map for which to search
offset (int) – Begin removing and returning items with rank == rank(found_item) + offset
return_type (int) – Value specifying what should be returned from the operation. This should be one of the Map Return Types values.
count (int) – If specified, the number of items to remove and return. If None, all items with rank greater than found_item are returned.
inverted (bool) – If True, the operation is inverted and items outside of the specified range are returned.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in operate or operate_ordered.The format of the dictionary should be considered an internal detail, and subject to change.
Note
This operation requires server version 4.3.0 or greater.
Examples for a key ordered map
{0: 6, 6: 12, 10: 18, 15: 24}
and return type ofaerospike.MAP_RETURN_KEY
:(value, offset, count) = [returned keys] # Remove and return all keys with values >= 6 (6, 0, None) = [0, 6, 10, 15] # No key with value 5 # The next greater value is 6 # So rank 0 = 6, and remove and return 2 keys # starting with the one with value 6 (5, 0, 2) = [0, 6] # No key with value 7 # The next greater value is 12 # So rank 0 = 12, rank -1 = 6 # We only remove and return one key (7, -1, 1) = [0] # Same scenario but remove and return three keys (7, -1, 3) = [0, 6, 10]
- aerospike_helpers.operations.map_operations.map_set_policy(bin_name: str, policy, ctx: list | None = None)
Creates a map_set_policy_operation.
This operation sets map policy attributes server-side for the designated map. Server does not return a value.
- Parameters:
bin_name (str) – The name of the bin containing the map.
policy (dict) – The map_policy dictionary. Note that the “map_write_flags” option in the map policy will be ignored in this operation.
ctx (list) – An optional list of nested CDT
cdt_ctx
context operation objects.
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.map_operations.map_size(bin_name: str, ctx: list | None = None)
Creates a map_size operation.
The operation returns the size of the map stored in the specified bin.
- Parameters:
- Returns:
A dictionary usable in
operate()
andoperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
aerospike_helpers.operations.bit_operations module
Helper functions to create bit operation dictionary arguments for:
aerospike.Client.operate
andaerospike.Client.operate_ordered
Certain batch operations listed in
aerospike_helpers.batch.records
Note
Bitwise operations require server version >= 4.6.0
Bit offsets are oriented left to right. Negative offsets are supported and start backwards from the end of the target bitmap.
- Offset examples:
0: leftmost bit in the map
4: fifth bit in the map
-1: rightmost bit in the map
-4: 3 bits from rightmost
Example:
import aerospike from aerospike_helpers.operations import bitwise_operations # Configure the client. config = {"hosts": [("127.0.0.1", 3000)]} # Create a client and connect it to the cluster. client = aerospike.client(config) key = ("test", "demo", "foo") five_ones_bin_name = "bitwise1" five_one_blob = bytearray([1] * 5) # Write the record. client.put(key, {five_ones_bin_name: five_one_blob}) # EXAMPLE 1: resize the five_ones bin to a bytesize of 10. ops = [bitwise_operations.bit_resize(five_ones_bin_name, 10)] _, _, bins = client.get(key) print("5 bytes: ", bins) # 5 bytes: {'bitwise1': b''} _, _, _ = client.operate(key, ops) _, _, newbins = client.get(key) print("After resize to 10 bytes: ", newbins) # After resize to 10 bytes: {'bitwise1': b''} # EXAMPLE 2: shrink the five_ones bin to a bytesize of 5 from the front. ops = [ bitwise_operations.bit_resize( five_ones_bin_name, 5, resize_flags=aerospike.BIT_RESIZE_FROM_FRONT ) ] _, _, _ = client.operate(key, ops) _, _, newbins = client.get(key) print("After resize to 5 bytes again: ", newbins) # After resize to 5 bytes again: {'bitwise1': b''} # Cleanup and close the connection to the Aerospike cluster. client.remove(key) client.close()
Example:
import aerospike
from aerospike import exception as e
from aerospike_helpers.operations import bitwise_operations
config = {'hosts': [('127.0.0.1', 3000)]}
client = aerospike.client(config)
key = ('test', 'demo', 'bit_example')
five_one_blob = bytearray([1] * 5)
five_one_bin = 'bitwise1'
# Precleanup
_, meta = client.exists(key)
if meta != None:
client.remove(key)
bit_policy = {
'bit_write_flags': aerospike.BIT_WRITE_DEFAULT,
}
client.put(key, {five_one_bin: five_one_blob})
# Example 1: read bits
ops = [
bitwise_operations.bit_get(five_one_bin, 0, 40)
]
_, _, results = client.operate(key, ops)
print(results)
# {'bitwise1': b''}
# Example 2: modify bits using the 'or' op, then read bits
# 0 = offset
# 8 = num bits to OR
# value to OR: 0xff
# value size is 1 byte
ops = [
bitwise_operations.bit_or(five_one_bin, 0, 8, 1, bytearray([255]), bit_policy),
bitwise_operations.bit_get(five_one_bin, 0, 40)
]
_, _, results = client.operate(key, ops)
print(results)
# {'bitwise1': b'ÿ'}
# Example 3: modify bits using the 'remove' op, then read bits'
# offset = 0
# # bytes to remove = 2
# Number of bits remaining = 24
ops = [
bitwise_operations.bit_remove(five_one_bin, 0, 2, bit_policy),
bitwise_operations.bit_get(five_one_bin, 0, 24)
]
_, _, results = client.operate(key, ops)
print(results)
# {'bitwise1': b''}
client.close()
See also
- aerospike_helpers.operations.bitwise_operations.bit_add(bin_name: str, bit_offset, bit_size, value, sign, action, policy=None)
Creates a bit_add_operation.
Creates a bit add operation. Server adds value to the bin at bit_offset for bit_size. bit_size must <= 64. If Sign is true value will be treated as a signed number. If an underflow or overflow occurs, as_bit_overflow_action is used. Server returns nothing.
- Parameters:
bin_name (str) – The name of the bin containing the map.
bit_offset (int) – The offset where the bits will be added.
bit_size (int) – How many bits of value to add.
value (int) – The value to be added.
sign (bool) – True: treat value as signed, False: treat value as unsigned.
action (aerospike.constant) – Action taken if an overflow/underflow occurs.
policy (dict) – The bit_policy dictionary. default: None.
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_and(bin_name: str, bit_offset, bit_size, value_byte_size, value, policy=None)
Creates a bit_and_operation.
Creates a bit and operation. Server performs an and op with value and bitmap in bin at bit_offset for bit_size. Server returns nothing.
- Parameters:
bin_name (str) – The name of the bin containing the map.
bit_offset (int) – The offset where the bits will be modified.
bit_size (int) – How many bits of value to and.
value_byte_size (int) – Length of value in bytes.
value (bytes, bytearray) – Bytes to be used in and operation.
policy (dict) – The bit_policy dictionary. default: None.
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_count(bin_name: str, bit_offset, bit_size)
Creates a bit_count_operation to be used with
aerospike.operate()
oraerospike.operate_ordered()
.Server returns an integer count of all set bits starting at bit_offset for bit_size bits.
- Parameters:
- Returns:
A dictionary usable in operate or operate_ordered. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_get(bin_name: str, bit_offset, bit_size)
Creates a bit_get_operation.
Server returns bits from bitmap starting at bit_offset for bit_size.
- Parameters:
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_get_int(bin_name: str, bit_offset, bit_size, sign)
Creates a bit_get_int_operation.
Server returns an integer formed from the bits read from bitmap starting at bit_offset for bit_size.
- Parameters:
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_insert(bin_name: str, byte_offset, value_byte_size, value, policy=None)
Creates a bit_insert_operation.
Server inserts the bytes from value into the bitmap at byte_offset. No value is returned.
- Parameters:
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_lscan(bin_name: str, bit_offset, bit_size, value)
Creates a bit_lscan_operation.
Server returns an integer representing the bit offset of the first occurrence of the specified value bit. Starts scanning at bit_offset for bit_size. Returns -1 if value not found.
- Parameters:
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_lshift(bin_name: str, bit_offset, bit_size, shift, policy=None)
Creates a bit_lshift_operation.
Server left shifts bitmap starting at bit_offset for bit_size by shift bits. No value is returned.
- Parameters:
bin_name (str) – The name of the bin containing the map.
bit_offset (int) – The offset where the bits will start being shifted.
bit_size (int) – The number of bits that will be shifted by shift places.
shift (int) – How many bits to shift by.
policy (dict) – The bit_policy dictionary. default: None.
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_not(bin_name: str, bit_offset, bit_size, policy=None)
Creates a bit_not_operation.
Server negates bitmap starting at bit_offset for bit_size. No value is returned.
- Parameters:
bin_name (str) – The name of the bin containing the map.
bit_offset (int) – The offset where the bits will start being scanned.
bit_size (int) – How many bits to scan.
policy (dict) – The bit_policy dictionary. default: None.
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_or(bin_name: str, bit_offset, bit_size, value_byte_size, value, policy=None)
Creates a bit_or_operation.
Creates a bit or operation. Server performs bitwise or with value and bitmap in bin at bit_offset for bit_size.
Server returns nothing.
- Parameters:
bin_name (str) – The name of the bin containing the map.
bit_offset (int) – The offset where the bits will start being compared.
bit_size (int) – How many bits of value to or.
value_byte_size (int) – Length of value in bytes.
value (bytes/byte array) – Value to be used in or operation.
policy (dict) – The bit_policy dictionary. default: None.
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_remove(bin_name: str, byte_offset, byte_size, policy=None)
Creates a bit_remove_operation to be used with
aerospike.operate()
oraerospike.operate_ordered()
.Remove bytes from bitmap at byte_offset for byte_size.
- Parameters:
bin_name (str) – The name of the bin containing the map.
byte_offset (int) – Position of bytes to be removed.
byte_size (int) – How many bytes to remove.
policy (dict) – The bit_policy dictionary. default: None.
- Returns:
A dictionary usable in operate or operate_ordered. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_resize(bin_name: str, byte_size, policy=None, resize_flags: int = 0)
Creates a bit_resize_operation to be used with
aerospike.operate()
oraerospike.operate_ordered()
.Change the size of a bytes bin stored in a record on the Aerospike Server.
- Parameters:
bin_name (str) – The name of the bin containing the map.
byte_size (int) – The new size of the bytes.
policy (dict) – The bit_policy dictionary. default: None.
resize_flags (int) – Bitwise Resize Flags modifying the resize behavior (default
aerospike.BIT_RESIZE_DEFAULT
), such asaerospike.BIT_RESIZE_GROW_ONLY | aerospike.BIT_RESIZE_FROM_FRONT
.
- Returns:
A dictionary usable in operate or operate_ordered. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_rscan(bin_name: str, bit_offset, bit_size, value)
Creates a bit_rscan_operation.
Server returns an integer representing the bit offset of the last occurrence of the specified value bit. Starts scanning at bit_offset for bit_size. Returns -1 if value not found.
- Parameters:
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_rshift(bin_name: str, bit_offset, bit_size, shift, policy=None)
Creates a bit_rshift_operation.
Server right shifts bitmap starting at bit_offset for bit_size by shift bits. No value is returned.
- Parameters:
bin_name (str) – The name of the bin containing the map.
bit_offset (int) – The offset where the bits will start being shifted.
bit_size (int) – The number of bits that will be shifted by shift places.
shift (int) – How many bits to shift by.
policy (dict) – The bit_policy dictionary. default: None.
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_set(bin_name: str, bit_offset, bit_size, value_byte_size, value, policy=None)
Creates a bit_set_operation to be used with
aerospike.operate()
oraerospike.operate_ordered()
.Set the value on a bitmap at bit_offset for bit_size in a record on the Aerospike Server.
- Parameters:
- Returns:
A dictionary usable in operate or operate_ordered. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_subtract(bin_name: str, bit_offset, bit_size, value, sign, action, policy=None)
Creates a bit_subtract_operation.
Server subtracts value from the bits at bit_offset for bit_size. bit_size must <= 64. If sign is true value will be treated as a signed number. If an underflow or overflow occurs, as_bit_overflow_action is used.
Server returns nothing.
- Parameters:
bin_name (str) – The name of the bin containing the map.
bit_offset (int) – The offset where the bits will be subtracted.
bit_size (int) – How many bits of value to subtract.
value (int) – The value to be subtracted.
sign (bool) – True: treat value as signed, False: treat value as unsigned.
action (aerospike.constant) – Action taken if an overflow/underflow occurs.
policy (dict) – The bit_policy dictionary. default: None.
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
- aerospike_helpers.operations.bitwise_operations.bit_xor(bin_name: str, bit_offset, bit_size, value_byte_size, value, policy=None)
Creates a bit_xor_operation.
Creates a bit and operation. Server performs bitwise xor with value and bitmap in bin at bit_offset for bit_size. Server returns nothing.
- Parameters:
bin_name (str) – The name of the bin containing the map.
bit_offset (int) – The offset where the bits will start being compared.
bit_size (int) – How many bits of value to xor.
value_byte_size (int) – Length of value in bytes.
value (bytes/byte array) – Value to be used in xor operation.
policy (dict) – The bit_policy dictionary. default: None.
- Returns:
A dictionary usable in
operate()
oroperate_ordered()
. The format of the dictionary should be considered an internal detail, and subject to change.
aerospike_helpers.operations.hll_operations module
Helper functions to create HyperLogLog operation dictionary arguments for:
aerospike.Client.operate
andaerospike.Client.operate_ordered
Certain batch operations listed in
aerospike_helpers.batch.records
HyperLogLog bins and operations allow for your application to form fast, reasonable approximations of members in the union or intersection between multiple HyperLogLog bins. HyperLogLog’s estimates are a balance between complete accuracy and efficient savings in space and speed in dealing with extremely large datasets.
Note
HyperLogLog operations require server version >= 4.9.0
See also
Example:
import aerospike
from aerospike_helpers.operations import hll_operations as hll_ops
from aerospike_helpers.operations import operations
NUM_INDEX_BITS = 12
NUM_MH_BITS = 24
# Configure the client.
config = {"hosts": [("127.0.0.1", 3000)]}
# Create a client and connect it to the cluster.
client = aerospike.client(config)
# Create customer keys
TEST_NS = "test"
TEST_SET = "demo"
customerNames = ["Amy", "Farnsworth", "Scruffy"]
keys = []
for customer in customerNames:
keys.append((TEST_NS, TEST_SET, customer))
itemsViewedPerCustomer = [
# [item1, item2, ... item500]
list("item%s" % str(i) for i in range(0, 500)), # Amy
list("item%s" % str(i) for i in range(0, 750)), # Farnsworth
list("item%s" % str(i) for i in range(250, 1000)), # Scruffy
]
for key, itemsViewed in zip(keys, itemsViewedPerCustomer):
customerName = key[2]
ops = [
operations.write("name", customerName),
hll_ops.hll_add("viewed", itemsViewed, NUM_INDEX_BITS, NUM_MH_BITS),
]
client.operate(key, ops)
# Find out how many items viewed Amy, Farnsworth, and Scruffy have in common.
farnsworthRecord = client.get(keys[1])
scruffyRecord = client.get(keys[2])
farnsworthViewedItems = farnsworthRecord[2]["viewed"]
scruffyViewedItems = scruffyRecord[2]["viewed"]
viewed = [farnsworthViewedItems, scruffyViewedItems]
ops = [
hll_ops.hll_get_intersect_count("viewed", viewed)
]
# Pass in Amy's key
_, _, res = client.operate(keys[0], ops)
print("Estimated items viewed intersection:", res["viewed"])
# Estimated items viewed intersection: 251
# Actual intersection: 250
# Find out how many unique products Amy, Farnsworth, and Scruffy have viewed.
ops = [hll_ops.hll_get_union_count("viewed", viewed)]
_, _, res = client.operate(keys[0], ops)
print("Estimated items viewed union:", res["viewed"])
# Estimated items viewed union: 1010
# Actual union: 1000
# Find the similarity of Amy, Farnsworth, and Scruffy's product views.
ops = [hll_ops.hll_get_similarity("viewed", viewed)]
_, _, res = client.operate(keys[0], ops)
print("Estimated items viewed similarity: %f%%" % (res["viewed"] * 100))
# Estimated items viewed similarity: 24.888393%
# Actual similarity: 25%
- aerospike_helpers.operations.hll_operations.hll_add(bin_name: str, values, index_bit_count=None, mh_bit_count=None, policy=None)
Creates a hll_add operation.
Server will add the values to the hll bin. If the HLL bin does not exist, it will be created with index_bit_count and/or mh_bit_count if they have been supplied.
Returns a dictionary to be used with
aerospike.Client.operate()
andaerospike.Client.operate_ordered()
.- Parameters:
bin_name (str) – The name of the bin to be operated on.
values – The values to be added to the HLL set.
index_bit_count – An optional number of index bits. Must be between 4 and 16 inclusive.
mh_bit_count – An optional number of min hash bits. Must be between 4 and 58 inclusive.
policy (dict) – An optional dictionary of HyperLogLog policies.
- aerospike_helpers.operations.hll_operations.hll_describe(bin_name)
Creates a hll_describe operation.
Server returns index and minhash bit counts used to create HLL bin in a list of integers. The list size is 2.
Returns a dictionary to be used with
aerospike.Client.operate()
andaerospike.Client.operate_ordered()
.- Parameters:
bin_name (str) – The name of the bin to be operated on.
- aerospike_helpers.operations.hll_operations.hll_fold(bin_name: str, index_bit_count)
Creates a hll_fold operation.
Servers folds index_bit_count to the specified value. This can only be applied when minhash bit count on the HLL bin is 0. Server does not return a value.
Returns a dictionary to be used with
aerospike.Client.operate()
andaerospike.Client.operate_ordered()
.- Parameters:
bin_name (str) – The name of the bin to be operated on.
index_bit_count – number of index bits. Must be between 4 and 16 inclusive.
- aerospike_helpers.operations.hll_operations.hll_get_count(bin_name)
Creates a hll_get_count operation.
Server returns estimated count of elements in the HLL bin.
Returns a dictionary to be used with
aerospike.Client.operate()
andaerospike.Client.operate_ordered()
.- Parameters:
bin_name (str) – The name of the bin to be operated on.
- aerospike_helpers.operations.hll_operations.hll_get_intersect_count(bin_name: str, hll_list)
Creates a hll_get_intersect_count operation.
Server returns estimate of elements that would be contained by the intersection of these HLL objects.
Returns a dictionary to be used with
aerospike.Client.operate()
andaerospike.Client.operate_ordered()
.
- aerospike_helpers.operations.hll_operations.hll_get_similarity(bin_name: str, hll_list)
Creates a hll_get_similarity operation.
Server returns estimated similarity of the HLL objects. Server returns a float.
Returns a dictionary to be used with
aerospike.Client.operate()
andaerospike.Client.operate_ordered()
.
- aerospike_helpers.operations.hll_operations.hll_get_union(bin_name: str, hll_list)
Creates a hll_get_union operation.
Server returns an HLL object that is the union of all specified HLL objects in hll_list with the HLL bin.
Returns a dictionary to be used with
aerospike.Client.operate()
andaerospike.Client.operate_ordered()
.
- aerospike_helpers.operations.hll_operations.hll_get_union_count(bin_name: str, hll_list)
Creates a hll_get_union_count operation.
Server returns the estimated count of elements that would be contained by the union of all specified HLL objects in the list with the HLL bin.
Returns a dictionary to be used with
aerospike.Client.operate()
andaerospike.Client.operate_ordered()
.
- aerospike_helpers.operations.hll_operations.hll_init(bin_name: str, index_bit_count=None, mh_bit_count=None, policy=None)
Creates a hll_init operation.
Server creates a new HLL or resets an existing HLL. If index_bit_count and mh_bit_count are None, an existing HLL bin will be reset but retain its configuration. If 1 of index_bit_count or mh_bit_count are set, an existing HLL bin will set that config and retain its current value for the unset config. If the HLL bin does not exist, index_bit_count is required to create it, mh_bit_count is optional. Server does not return a value.
Returns a dictionary to be used with
aerospike.Client.operate()
andaerospike.Client.operate_ordered()
.- Parameters:
bin_name (str) – The name of the bin to be operated on.
index_bit_count – An optional number of index bits. Must be between 4 and 16 inclusive.
mh_bit_count – An optional number of min hash bits. Must be between 4 and 58 inclusive.
policy (dict) – An optional dictionary of HyperLogLog policies.
- aerospike_helpers.operations.hll_operations.hll_refresh_count(bin_name: str)
Creates a hll_refresh_count operation.
Server updates the cached count if it is stale. Server returns the count.
Returns a dictionary to be used with
aerospike.Client.operate()
andaerospike.Client.operate_ordered()
. :param bin_name: The name of the bin to be operated on. :type bin_name: str
- aerospike_helpers.operations.hll_operations.hll_set_union(bin_name: str, hll_list, policy=None)
Creates a hll_set_union operation.
Server sets the union of all specified HLL objects with the HLL bin. Server returns nothing.
Returns a dictionary to be used with
aerospike.Client.operate()
andaerospike.Client.operate_ordered()
.- Parameters:
bin_name (str) – The name of the bin to be operated on.
hll_list (list) – The HLLs who’s union will be set.
policy (dict) – An optional dictionary of HyperLogLog policies.
aerospike_helpers.operations.expression_operations module
This module provides helper functions to produce dictionaries to be used with:
aerospike.Client.operate
andaerospike.Client.operate_ordered
Certain batch operations listed in
aerospike_helpers.batch.records
Expression operations support reading and writing the result of Aerospike expressions.
Note
Requires server version >= 5.6.0
- aerospike_helpers.operations.expression_operations.expression_read(bin_name: str, expression: _BaseExpr, expression_read_flags: int = 0)
Create an expression read operation dictionary.
Reads and returns the value produced by the evaluated expression.
- Parameters:
bin_name (str) – The name of the bin to read from. Even if no bin is being read from, the value will be returned with this bin name.
expression – A compiled Aerospike expression, see aerospike_helpers.expressions package.
expression_read_flags (int) – Read Expression Flags (default
aerospike.EXP_READ_DEFAULT
)
- Returns:
A dictionary to be passed to operate or operate_ordered.
Example:
# Read the value of int bin "balance". # Let 'client' be a connected aerospike client. # Let int bin 'balance' == 50. from aerospike_helpers.operations import expression_operations as expressions from aerospike_helpers.expressions import * expr = IntBin("balance").compile() ops = [ expressions.expression_read("balance", expr) ] _, _, res = client.operate(self.key, ops) print(res) # EXPECTED OUTPUT: {"balance": 50}
- aerospike_helpers.operations.expression_operations.expression_write(bin_name: str, expression: _BaseExpr, expression_write_flags: int = 0)
Create an expression write operation dictionary.
Writes the value produced by the evaluated expression to the supplied bin.
- Parameters:
bin_name (str) – The name of the bin to write to.
expression – A compiled Aerospike expression, see aerospike_helpers.expressions package.
expression_write_flags (int) – Write Expression Flags such as
aerospike.EXP_WRITE_UPDATE_ONLY | aerospike.EXP_WRITE_POLICY_NO_FAIL
(defaultaerospike.EXP_WRITE_DEFAULT
).
- Returns:
A dictionary to be passed to operate or operate_ordered.
Example:
# Write the value of int bin "balance" + 50 back to "balance". # Let 'client' be a connected aerospike client. # Let int bin 'balance' == 50. from aerospike_helpers.operations import expression_operations as expressions from aerospike_helpers.expressions import * expr = Add(IntBin("balance"), 50).compile() ops = [ expressions.expression_write("balance", expr) ] client.operate(self.key, ops) _, _, res = client.get(self.key) print(res) # EXPECTED OUTPUT: {"balance": 100}