public sealed class ManagedSessionReference documentation and code samples for the Google Cloud Spanner v1 API class ManagedSession.
Manages an underlying Spanner multiplex session and its lifecycle.
Namespace
Google.Cloud.Spanner.V1Assembly
Google.Cloud.Spanner.V1.dll
Constructors
ManagedSession(ManagedSessionOptions)
public ManagedSession(ManagedSessionOptions options)Creates a ManagedSession for the given options.
| Parameter | |
|---|---|
| Name | Description |
options |
ManagedSessionOptions |
Methods
BatchWriteAsync(BatchWriteRequest, CallSettings)
public Task<AsyncResponseStream<BatchWriteResponse>> BatchWriteAsync(BatchWriteRequest request, CallSettings callSettings)Executes a BatchWrite RPC asynchronously, returning a stream of responses.
| Parameters | |
|---|---|
| Name | Description |
request |
BatchWriteRequestThe batch write request. Must not be null. |
callSettings |
CallSettingsIf not null, applies overrides to this RPC call. |
| Returns | |
|---|---|
| Type | Description |
TaskAsyncResponseStreamBatchWriteResponse |
A task representing the asynchronous operation. When the task completes, the result is the response stream of BatchWriteResponse objects. |
This method modifies the request to include the session name from this managed session.
BeginTransactionAsync(TransactionOptions, bool, bool, CancellationToken)
public Task<ManagedTransaction> BeginTransactionAsync(TransactionOptions transactionOptions, bool singleUse, bool shared, CancellationToken cancellationToken)Creates a ManagedTransaction associated to this session.
| Parameters | |
|---|---|
| Name | Description |
transactionOptions |
TransactionOptions |
singleUse |
bool |
shared |
bool |
cancellationToken |
CancellationToken |
| Returns | |
|---|---|
| Type | Description |
TaskManagedTransaction |
|
Note that obtaining a ManagedTransaction won't immediately start a Spanner transaction. Instead, a ManagedTransaction will start a Spanner transaction when needed, usually when exeucting the first command, and will manage the Spanner transaction lifecycle.
EnsureFreshAsync(CancellationToken)
public Task EnsureFreshAsync(CancellationToken cancellationToken)Ensures the underlying Spanner session is fresh.
| Parameter | |
|---|---|
| Name | Description |
cancellationToken |
CancellationToken |
| Returns | |
|---|---|
| Type | Description |
Task |
|
Note that session freshness and lifecycle is handled automatically, so this method rarely needs to be called, except maybe after the ManagedSession has been created or has been idle for a long time, and before executing the first command, to make certain refreshing the session does not penalize, latency wise, the first few commands.