aerospike_helpers.batch package
aerospike_helpers.batch.records module
Classes for the use with client batch APIs batch_write()
, batch_operate()
,
batch_apply()
, batch_remove()
.
- class aerospike_helpers.batch.records.Apply(key: tuple, module: str, function: str, args: List[Any], policy: Dict | None = None)
Bases:
BatchRecord
BatchApply is used for executing Batch UDF (user defined function) apply operations with batch_write and retrieving results.
- record
The record corresponding to the requested key.
- Type:
- in_doubt
Is it possible that the write transaction completed even though an error was generated. This may be the case when a client error occurs (like timeout) after the command was sent to the server.
- Type:
- policy
An optional dictionary of batch apply policy flags.
- Type:
Batch Apply Policies, optional
- __init__(key: tuple, module: str, function: str, args: List[Any], policy: Dict | None = None) None
Example:
# Create a batch Apply to apply UDF "test_func" to bin "a" from the record. # Assume that "test_func" takes a bin name string as an argument. # Assume the appropriate UDF module has already been registered. import aerospike_helpers.operations as op module = "my_lua" function = "test_func" bin_name = "a" args = [ bin_name ] namespace = "test" set = "demo" user_key = 1 key = (namespace, set, user_key) ba = Apply(key, module, function, args)
- class aerospike_helpers.batch.records.BatchRecord(key: tuple)
Bases:
object
BatchRecord provides the base fields for BatchRecord objects.
BatchRecord should usually be read from as a result and not created by the user. Its subclasses can be used as input to batch_write. Client methods
batch_apply()
,batch_operate()
,batch_remove()
with batch_records field as a list of these BatchRecord objects containing the batch request results.- record
The record corresponding to the requested key.
- Type:
- in_doubt
Is it possible that the write transaction completed even though an error was generated. This may be the case when a client error occurs (like timeout) after the command was sent to the server.
- Type:
- __weakref__
list of weak references to the object
- class aerospike_helpers.batch.records.BatchRecords(batch_records: List[BatchRecord] | None = None)
Bases:
object
BatchRecords is used as input and output for multiple batch APIs.
- batch_records
A list of BatchRecord subtype objects used to define batch operations and hold results. BatchRecord Types can be Remove, Write, Read, and Apply.
- Type:
- result
The status code of the last batch call that used this BatchRecords.
0
if all batch subtransactions succeeded (or if the only failures wereFILTERED_OUT
orRECORD_NOT_FOUND
) Not0
if an error occurred. The most common error is-16
(One or more batch sub transactions failed).- Type:
- __init__(batch_records: List[BatchRecord] | None = None) None
Example:
import aerospike import aerospike_helpers.operations.operations as op from aerospike_helpers.batch.records import BatchRecords, Remove, Write, Read # Setup config = { "hosts": [("127.0.0.1", 3000)] } client = aerospike.client(config) namespace = "test" set_ = "demo" keys = [ (namespace, set_, 1), (namespace, set_, 2), (namespace, set_, 3), ] bin_name = "id" for key in keys: client.put(key, {bin_name: 1}) # Create a BatchRecords to remove a record, write a bin, and read a bin. brs = BatchRecords( [ Remove( key=keys[0], ), Write( key=keys[1], ops=[ op.write(bin_name, 100), op.read(bin_name), ] ), Read( key=keys[2], ops=[ op.read(bin_name) ] ) ] ) # Note this call will mutate brs and set results in it. client.batch_write(brs) for br in brs.batch_records: print(br.result) print(br.record) # 0 # (('test', 'demo', 1, bytearray(b'...')), {'ttl': 4294967295, 'gen': 0}, {}) # 0 # (('test', 'demo', 2, bytearray(b'...')), {'ttl': 2592000, 'gen': 4}, {'id': 100}) # 0 # (('test', 'demo', 3, bytearray(b'...')), {'ttl': 2592000, 'gen': 3}, {'id': 1})
- __weakref__
list of weak references to the object
- class aerospike_helpers.batch.records.Read(key: tuple, ops: List[Dict] | None, read_all_bins: bool = False, meta: dict | None = None, policy: Dict | None = None)
Bases:
BatchRecord
Read is used for executing Batch read operations with batch_write and retrieving results.
- in_doubt
Is it possible that the write transaction completed even though an error was generated. This may be the case when a client error occurs (like timeout) after the command was sent to the server.
- Type:
- ops
list of aerospike operation dictionaries to perform on the record at key.
- policy
An optional dictionary of batch read policy flags.
- Type:
Batch Read Policies, optional
- __init__(key: tuple, ops: List[Dict] | None, read_all_bins: bool = False, meta: dict | None = None, policy: Dict | None = None) None
Example:
# Create a batch Read to read bin "a" from the record. import aerospike import aerospike_helpers.operations as op from aerospike_helpers.batch.records import Read bin_name = "a" namespace = "test" set = "demo" user_key = 1 key = (namespace, set, user_key) ops = [ op.read(bin_name) ] meta={"gen": 1, "ttl": aerospike.TTL_NEVER_EXPIRE} br = Read(key, ops, meta=meta)
- class aerospike_helpers.batch.records.Remove(key: tuple, policy: Dict | None = None)
Bases:
BatchRecord
Remove is used for executing Batch remove operations with batch_write and retrieving results.
- record
The record corresponding to the requested key.
- Type:
- in_doubt
Is it possible that the write transaction completed even though an error was generated. This may be the case when a client error occurs (like timeout) after the command was sent to the server.
- Type:
- policy
An optional dictionary of batch remove policy flags.
- Type:
Batch Remove Policies, optional
- class aerospike_helpers.batch.records.Write(key: tuple, ops: List[Dict], meta: dict | None = None, policy: Dict | None = None)
Bases:
BatchRecord
Write is used for executing Batch write operations with batch_write and retrieving batch write results.
- in_doubt
Is it possible that the write transaction completed even though an error was generated. This may be the case when a client error occurs (like timeout) after the command was sent to the server.
- Type:
- ops
A list of aerospike operation dictionaries to perform on the record at key.
- policy
An optional dictionary of batch write policy flags.
- Type:
Batch Write Policies, optional
- __init__(key: tuple, ops: List[Dict], meta: dict | None = None, policy: Dict | None = None) None
Example:
# Create a batch Write to increment bin "a" by 10 and read the result from the record. import aerospike import aerospike_helpers.operations as op from aerospike_helpers.batch.records import Write bin_name = "a" namespace = "test" set = "demo" user_key = 1 key = (namespace, set, user_key) ops = [ op.increment(bin_name, 10), op.read(bin_name) ] meta={"gen": 1, "ttl": aerospike.TTL_NEVER_EXPIRE} bw = Write(key, ops, meta=meta)