New Features and Behaviour Changes in 1.1.0
The 1.1 release of the .NET Client Library contains a series of new API methods designed to provide developers with more details about the success or failure of an operation performed by the client.
The existing API methods remain in place and as such, these
changes are not breaking. Each of the new methods has the
standard API method name prefixed by
Execute. For example
Store becomes
ExecuteStore.
var storeResult = client.ExecuteStore(StoreMode.Set, "foo", "bar"); if (! result.Success) { Console.WriteLine("Operation failed: {0}", result.Message); }
Each of the new Execute methods returns an instance of an
IOperationResult, with is extended by various
operation specific interfaces -
IGetOperationResult,
IStoreOperationResult,
IConcatOperationResult,
IMutateOperationResult and
IRemoveOperationResult.
IOperationResult defines common properties
available to all results returned by Execute methods.
IOperationResult opertionResult = client.Store(StoreMode.Set, "foo", "bar"); //Was the operation successful (i.e., no errors or exceptions)? Console.WriteLine("Success: " + operationResult.Success); //Print out possible error, warning or informational message Console.WriteLine("Message: " + operationResult.Message); //Print out a caught exception Console.WriteLine("Exception: " + operationResult.Exception.Message); //Print out status code (nullable) Console.WriteLine("StatusCode: " + operationResult.StatusCode); //Print out InnerResult, which is populated on handled failures (i.e., IO exceptions) Console.WriteLine("InnerResult: " + operationResult.InnerResult.Message);
Store, Get, Mutate and Concat operation results all return Cas values.
var getResult = client.ExecuteGet("foo"); //Print out the Cas value Console.WriteLine("Cas value for 'foo':" + getResult.Cas);
Get operation results also expose HasValue and Value properties.
var getResult = client.ExecuteGet("foo"); //Print out whether getResult contains a value (shortcut for value null check) Console.WriteLine("getResult HasValue: " + getResult.HasValue); //Print out the item value Console.WriteLine("Value for 'foo':" + getResult.Value);
Most failures are likely to fall into one of two categories. The first are conditions that the server won't allow. For example, a Cas operation with an expired CAS value would be a failure. Attempting to add a key when that key already exists would also be failure. The second category of likely failures would occur when the client can't connect to a node.
Both categories of failures are likely to be reported by
lower-level components within the client library. These
components handle these errors gracefully and then log the
problem. Before 1.1, these failure conditions were swallowed and
did not propagate up to the caller. As a consequence, it is a
good idea to check the InnerResult for a
failed operation result.