SyncClient¶
- class aerospike_sdk.sync.client.SyncClient[source]¶
Bases:
objectConnect to Aerospike and run the SDK API without
async/await.Method shapes match
Client; return types are synchronous counterparts (for exampleSyncQueryBuilder,SyncSession).Example:
with SyncClient("localhost:3000") as client: for row in client.query( namespace="test", set_name="users" ).execute(): if row.record: print(row.record.bins)
- Raises:
RuntimeError – If constructed or used while an asyncio event loop is already running in the thread (use
Clientinstead).
See also
Client: Native async client.create_session(): Session-scopedBehavior.- query(arg1=None, arg2=None, *keys, namespace=None, set_name=None, dataset=None, key=None, keys_list=None, behavior=None)[source]¶
- Overloads:
self, dataset (DataSet), behavior (Optional[Behavior])
self, key (Key), behavior (Optional[Behavior])
self, keys (List[Key]), behavior (Optional[Behavior])
self, keys (Key), behavior (Optional[Behavior])
self, namespace (str), set_name (str), behavior (Optional[Behavior])
Create a query builder (synchronous).
Supports the same calling styles as
Client.query, including multi-key varargs. Returns a wrapper that executes queries synchronously.- Parameters:
arg1 (
Union[DataSet,Key,List[Key],str,None]) – Optional first positional (DataSet, key, list of keys, or namespace string when paired witharg2as set name).arg2 (
Optional[str]) – 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).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]) – OptionalBehaviorfor this builder (same semantics asClient.query).
- Returns:
- Configured for the requested namespace, set,
and/or keys.
- Return type:
- index(namespace=None, set_name=None, *, dataset=None, behavior=None)[source]¶
- Overloads:
self, dataset (DataSet), behavior (Optional[Behavior])
self, namespace (str), set_name (str), behavior (Optional[Behavior])
Create a secondary-index builder (synchronous).
Same arguments as
index().create()/drop()run on the client’s event loop.- Returns:
Configured for the requested namespace and set.
- Return type:
See also
IndexBuilder: Async implementation.
- truncate(dataset, before_nanos=None)[source]¶
Truncate (delete all records) from a set (synchronous).
This method deletes all records in the specified set. This operation cannot be undone.
- Parameters:
- Return type:
Example:
users = DataSet.of("test", "users") client.truncate(users) # Truncate only records older than a specific time import time cutoff_time = time.time_ns() - (24 * 60 * 60 * 10**9) # 24 hours ago client.truncate(users, before_nanos=cutoff_time)
- register_udf(body, server_path, language=UDFLang.LUA, *, policy=None)[source]¶
Register a UDF module from bytes (synchronous).
- Return type:
RegisterTask
- register_udf_from_file(client_path, server_path, language=UDFLang.LUA, *, policy=None)[source]¶
Register a UDF module from a local file (synchronous).
- Return type:
RegisterTask
- remove_udf(server_path, *, policy=None)[source]¶
Remove a UDF module from the cluster (synchronous).
- Return type:
UdfRemoveTask
- create_session(behavior=None)[source]¶
Create a session with the specified behavior (synchronous).
A session represents a logical connection to the cluster with specific behavior settings that control how operations are performed (timeouts, retry policies, consistency levels, etc.).
- Parameters:
behavior (
Optional[Behavior]) – The behavior configuration for the session. If None, uses Behavior.DEFAULT.- Return type:
- Returns:
A
SyncSessionsharing this client’s event-loop manager and applyingbehaviorto operations.
Example:
session = client.create_session() from datetime import timedelta fast = Behavior.DEFAULT.derive_with_changes( name="fast", total_timeout=timedelta(seconds=5), ) session = client.create_session(fast)
See also
create_session():Async equivalent.
- create_transactional_session(behavior=None)[source]¶
Create a synchronous multi-record transaction (MRT) session.
Allocates a fresh
Txnon entry. Operations chained off the returned session (tx.upsert(...),tx.query(...),tx.batch(), …) auto-participate in the transaction — every builder stampspolicy.txn = tx.txnunder the hood. On clean exit the transaction is committed; if an exception propagates out of thewithblock it is aborted.Multi-record transactions require an Aerospike server running in strong-consistency (SC) mode on the target namespace.
- Parameters:
behavior (
Optional[Behavior]) – OptionalBehaviorfor operations inside the transaction. Defaults toBehavior.DEFAULTwhen omitted.- Return type:
- Returns:
A
SyncTransactionalSessionbound to this client and behavior.
Example:
with client.create_transactional_session() as tx: tx.upsert(accounts.id("A")).bin("balance").set_to(100).execute() tx.upsert(accounts.id("B")).bin("balance").set_to(200).execute()
See also
transaction_session():Async equivalent.