DataSet¶
- class aerospike_sdk.dataset.DataSet[source]¶
Bases:
objectPair a namespace and set name for building
Keyvalues.Use
of()as the factory, thenid()for one key orids()for many. Pass keys toquery(),upsert(), and other session APIs.Example
users = DataSet.of(“test”, “users”) k = users.id(“user-123”) ks = users.ids(“a”, “b”, “c”)
See also
Session: Operations on keys.- __init__(namespace, set_name)[source]¶
Create a DataSet instance.
- Parameters:
- Raises:
ValueError – If namespace or set_name is empty
- static of(namespace, set_name)[source]¶
Construct a dataset handle for
namespaceandset_name.- Parameters:
- Return type:
- Returns:
A
DataSetsharing the same equality/hash for the pair.- Raises:
ValueError – If either string is empty.
Example
orders = DataSet.of(“prod”, “orders”)
- id(identifier)[source]¶
Build one
Keyfor this namespace and set.- Parameters:
identifier (
Union[str,int,bytes]) – User key value (string, integer, or bytes).- Return type:
Key- Returns:
A
Keybound to this dataset’s namespace/set.
Example
users = DataSet.of(“test”, “users”) key_str = users.id(“user123”) key_int = users.id(12345) key_bin = users.id(b”pk”)
See also
ids(): Multiple keys in one call.
- id_from_digest(digest)[source]¶
Create an Aerospike key from a digest.
- Parameters:
digest (
Union[str,bytes]) – The digest as a hex string or bytes- Return type:
Key- Returns:
A new Key instance created from the digest
Example:
users = DataSet.of("test", "users") # From hex string key = users.id_from_digest("a1b2c3d4...") # From bytes key = users.id_from_digest(b"\xa1\xb2\xc3...")
- id_for_object(obj)[source]¶
Create an Aerospike key from an object identifier. Supports String, Integer, Long, and byte array types.
- Parameters:
obj (
object) – The object to use as the key identifier- Return type:
Key- Returns:
A new Key instance
- Raises:
TypeError – If the object type is not supported
Example:
users = DataSet.of("test", "users") key1 = users.id_for_object("user123") # String key key2 = users.id_for_object(123) # Integer key key3 = users.id_for_object(12345) # Integer key key4 = users.id_for_object(b"bytes") # Bytes key
- ids(*identifiers)[source]¶
- Overloads:
self, identifiers (str) → List[Key]
self, identifiers (int) → List[Key]
self, identifiers (bytes) → List[Key]
self, identifiers (List[Union[str, int, bytes]]) → List[Key]
Build many keys sharing this dataset’s namespace and set.
Call either with several positional identifiers (
ids("a", "b", "c")) or with a single list (ids(["a", "b", "c"])). Mixed-type lists useid_for_object()per element when the single-list form is used.- Parameters:
*identifiers (
Union[str,int,bytes]) – One or more identifiers, or exactly one list of identifiers.- Returns:
A list of
Keyinstances in input order.- Raises:
TypeError – If list elements are not supported key types.
Example
users = DataSet.of(“test”, “users”) keys1 = users.ids(“u1”, “u2”, “u3”) keys2 = users.ids([“u1”, “u2”]) keys3 = users.ids(1, 2, 3)
See also
id(): Single-key helper.
- ids_from_digests(*digests)[source]¶
Create multiple Aerospike keys from digests.
- Parameters:
*digests (
Union[str,bytes]) – Variable number of digests (hex strings or bytes)- Return type:
List[Key]- Returns:
A list of Key instances created from the digests
Example:
users = DataSet.of("test", "users") keys = users.ids_from_digests("digest1", "digest2", b"digest3")