SurrealCS Client
The SurrealCS client is a simple key-value store client that can be used to interact with the SurrealCS server.
Connections
The connection between the client and the server consists of a pool of TCP connections. Lets say we want to create a pool of 3 connections, we can do this with the following code:
use create_connection_pool;
let ids: = create_connection_pool.await.unwrap;
The create_connection_pool
function returns a Vec<usize>
which is the indexes of the connection in the pool. This index is not really needed, as allocation is done automatically, but it can be useful for debugging purposes. If the number of
connections is not specified, the default number of connections will be the number of cores on the machine.
We can also create a single connection with the following code:
use ;
let id = create_connection.await.unwrap;
The create_connection
function returns a usize
which is the index of the connection in the pool. This index is not really needed, as allocation is done automatically, but it can be useful for debugging purposes. The send_to_router
is a function
that sends to the global connection allocator. You can also create your own function that handles the sending to a connection
allocator. However, you must also manage your own connection pool. This can be useful for testing purposes or if you wanted
to have different connection pools to different servers.
Strict Transactions
Strict transactions are when the functions available to the transaction handle are restricted based on the state of the transaction. We can also exploit the Rust compiler to check the state of the transaction, meaning that we can strict a function input of a transaction that only has a particular state if needed by the following:
We can start a transaction with the following code:
use ;
use ;
let transaction: = new.await.unwrap;
// begin a transaction with a put
let message = Put;
// returns a Transaction<InProgress>
let = transaction..await.unwrap;
match outcome ;
// send a get message
let message = Get;
// returns a Transaction<InProgress>
let outcome = transaction..await.unwrap;
let outcome = match outcome ;
// commit with a get transaction
let message = Get;
// returns a Transaction<Committed>
// We also have an empty_commit function that can be used to commit a transaction without
// any additional messages
let = transaction..await.unwrap;
It must be noted that we utilize a BridgeHandle
when sending messages to our transaction actor
associated with the handle. This handle facilitates the sending of the message to the actor and
receiving the response from the actor. We have a handle to allow users to implement their own
handles if they wish to do so. The handle also helps with unit testing to see how the transaction
handle handles multiple edgecases. If you want to implement your own handle, you can do so by
implement the surrealcs::transactions::interface::bridge::SendToTransactionClientActor
for a struct. The SendToTransactionClientActor
does not reference the state of the
struct implementing the trait.
Relaxed Transactions
Relaxed transactions are built on top of strict transactions. Please read the strict transactions section before reading this section.
Relaxed transactions are transactions that allow the user to send any message and the state does not change. To create a relaxed transaction, we can do the following:
use ;
let transaction: = new.await.unwrap;
You can then perform a range of operations on the transaction without the state changing. This is useful for legacy systems that are not designed to support strict transactions.