SyncSession¶
- class aerospike_sdk.sync.session.SyncSession[source]¶
Bases:
objectRun session-scoped reads and writes without
async/await.Constructed by
SyncClient.create_session, not by callingSyncSession(...)directly. Each method delegates toSessionon a shared per-thread loop; return types are sync wrappers where the async API would return a coroutine or async stream.See also
Session: Async API and behaviorsemantics.
- __init__(async_session, loop_manager)[source]¶
Wrap
async_session; useSyncClient.create_session()instead.- Parameters:
async_session (
Session) – Connected async session (same behavior binding).loop_manager (
_EventLoopManager) – Loop manager shared with the parentSyncClient.
- query(arg1=None, arg2=None, *keys, namespace=None, set_name=None, dataset=None, key=None, keys_list=None, behavior=None)[source]¶
Start a read or secondary-index query (synchronous session).
Same shapes as
aerospike_sdk.aio.session.Session.query(), with this session’s behavior applied on the underlying async builder.- Parameters:
arg1 (
Union[DataSet,Key,List[Key],str,None]) – Positional dataset, key, list of keys, or namespace string (when paired witharg2as set name).arg2 (
Union[str,Key,None]) – Whenarg1is a namespace, the set name; otherwise may be a second key when passing multiple keys positionally.*keys (
Key) – Additional keys when the first positional argument is a key.namespace (
Optional[str]) – Keyword namespace (withset_name) when not using a dataset.set_name (
Optional[str]) – Keyword set name (withnamespace).key (
Optional[Key]) – Keyword single key.keys_list (
Optional[List[Key]]) – Keyword list of keys for batch read.behavior (
Optional[Behavior]) – Optional per-query behavior override (same as async session).
- Return type:
- Returns:
- batch()[source]¶
Start a multi-key batch of mixed write operations (synchronous).
Chain
insert,update,upsert,replace,delete, and bin builders, thenexecute()for aSyncRecordStream.- Return type:
- Returns:
- Raises:
RuntimeError – If the client is not connected (from the async session).
Example:
stream = ( session.batch() .insert(key1).put({"name": "Alice", "age": 25}) .update(key2).bin("counter").add(1) .execute() ) for row in stream: print(row.key, row.result_code)
See also
- transaction_session()[source]¶
Alias for
begin_transaction().- Return type:
- Returns:
SyncTransactionalSessionbound to this session’s client and behavior.
See also
begin_transaction(): Preferred entry point.transaction_session(): Async equivalent.
- begin_transaction()[source]¶
Start a multi-record transaction (MRT) using this session’s behavior.
Returns a context manager that allocates a fresh
Txn. Every operation run on the returned session auto-participates in the transaction — builders stamppolicy.txn = tx.txnunder the hood, so user code never touches a policy object. On clean exit the transaction is committed; if an exception propagates out of thewithblock the transaction is aborted.Example
>>> with session.begin_transaction() as tx: ... tx.upsert(accounts.id("A")).bin("balance").set_to(100).execute() ... tx.upsert(accounts.id("B")).bin("balance").set_to(200).execute()
- Return type:
- Returns:
SyncTransactionalSessionbound to this session’s client and behavior.
See also
transaction_session(): Alias for this method.do_in_transaction(): Run a callable inside a retrying MRT.begin_transaction(): Async equivalent.
- do_in_transaction(operation, *, max_attempts=5, sleep_between_retries=0.0)[source]¶
Run a callable inside a retrying multi-record transaction.
Creates a
SyncTransactionalSession, invokesoperation(tx)insidewith, and retries the whole block when the server signals a transient conflict (MRT_BLOCKED,MRT_VERSION_MISMATCH, orTXN_FAILED). On any non-transient failure the transaction is aborted and the exception re-raised.- Parameters:
operation (
Callable[[SyncTransactionalSession],Any]) – Synchronous callable accepting aSyncTransactionalSessionand performing zero or more operations on it. Its return value is returned fromdo_in_transaction().max_attempts (
int) – Maximum total attempts (initial + retries). Must be>= 1. Defaults to5.sleep_between_retries (
float) – Optional seconds totime.sleepbetween retries.0(the default) retries immediately.
- Return type:
- Returns:
Whatever
operationreturns on the successful attempt.- Raises:
ValueError – If
max_attempts < 1.AerospikeError – The last-seen transient error after
max_attemptsexhausted retries, or any non-transient error raised byoperation.
Example
>>> def transfer(tx): ... tx.upsert(accounts.id("A")).bin("bal").add(-10).execute() ... tx.upsert(accounts.id("B")).bin("bal").add(10).execute() ... return "ok" >>> result = session.do_in_transaction(transfer)
See also
begin_transaction(): Manual MRT lifecycle.SyncTransactionalSessiondo_in_transaction(): Async equivalent.
- background_task()[source]¶
Start a background dataset task chain (synchronous).
- Return type:
- Returns:
See also
- execute_udf(*keys)[source]¶
Begin a foreground UDF invocation on the given keys (synchronous).
- Return type:
- Returns:
See also
- index(namespace=None, set_name=None, *, dataset=None, behavior=None)[source]¶
Create a secondary-index builder for this namespace/set (synchronous).
- Raises:
ValueError – If
namespaceandset_nameare missing and nodatasetis provided.- Return type:
- Returns:
See also
- truncate(dataset, before_nanos=None)[source]¶
Truncate (delete all records) from a set (synchronous).
- Return type:
- is_namespace_sc(namespace)[source]¶
Check if a namespace is in strong-consistency (SC) mode.
- Parameters:
namespace (
str) – The namespace name to check.- Return type:
- Returns:
Trueif the namespace is configured for strong consistency,Falseotherwise.- Raises:
RuntimeError – If the underlying client is not connected.
ValueError – If the namespace is unknown or the info command fails.
Example:
if session.is_namespace_sc("test_sc"): print("Namespace is SC — MRTs are supported here.")
See also
is_namespace_sc():Async equivalent.
- info(command=None)[source]¶
- Overloads:
self → SyncInfoCommands
self, command (str) → Dict[str, str]
Execute info commands or get the SyncInfoCommands helper (synchronous).
With no argument, returns SyncInfoCommands for high-level helpers and info_on_all_nodes(). With a command string, runs the raw info command and returns its result.
Example:
response = session.info("sindex-list") info = session.info() by_node = info.info_on_all_nodes("build")
- upsert(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]¶
Create an upsert write segment (synchronous).
- Return type:
- insert(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]¶
Create an insert write segment (synchronous).
- Return type:
- update(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]¶
Create an update write segment (synchronous).
- Return type:
- replace(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]¶
Create a replace write segment (synchronous).
- Return type:
- replace_if_exists(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]¶
Create a replace-if-exists write segment (synchronous).
- Return type:
- delete(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]¶
Create a delete write segment (synchronous).
- Return type:
- touch(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]¶
Create a touch write segment (synchronous).
- Return type: