# `Aerospike.Txn`
[🔗](https://github.com/luisgabrielroldan/aerospike_driver/blob/v0.3.1/lib/aerospike/txn.ex#L1)

Transaction handle for multi-record transactions.

`Aerospike.Txn` is an immutable handle that identifies a transaction in
progress. Create one with `new/0` or `new/1`, then pass it as the `:txn`
option to transaction-aware single-record commands.

Creating this struct does not start a transaction by itself. Runtime state
lives in the started cluster's ETS tables and is initialized when
`Aerospike.transaction/2` or `Aerospike.transaction/3` enters the callback.
This struct only carries the transaction identifier and timeout.

The handle is only valid against the cluster that initialized it. A fresh
`%Aerospike.Txn{}` or a handle reused against another cluster has no runtime
state behind it, so transaction commands reject it.

Passing the same `%Aerospike.Txn{}` to multiple concurrent processes is
undefined behavior. The tracking row is shared mutable state, and the driver
does not serialize concurrent updates around one transaction handle.

# `option`

```elixir
@type option() :: {:timeout, non_neg_integer()}
```

Option accepted by `new/1`.

# `opts`

```elixir
@type opts() :: [option()]
```

Keyword options accepted by `new/1`.

# `t`

```elixir
@type t() :: %Aerospike.Txn{id: integer(), timeout: non_neg_integer()}
```

Multi-record transaction handle.

`id` is the signed 64-bit transaction identifier sent to the server.
`timeout` is the multi-record transaction timeout in milliseconds, where `0`
asks the server to use its configured default duration.

# `new`

```elixir
@spec new() :: t()
```

Creates a new transaction handle with a random signed int64 ID.

# `new`

```elixir
@spec new(opts()) :: t()
```

Creates a new transaction handle with the given options.

Options:

  * `:timeout` — transaction timeout in milliseconds. `0` asks the server to
    use its configured multi-record transaction duration.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
