Today we are releasing the new Couchbase .NET SDK for General Availability! This is a complete rewrite of the SDK and is based off of the Couchbase SDK 2.0 Specification, meaning it maintains a consistent interface with all of the other Couchbase 2.0 SDK’s and it shares common transcoding and flags for interacting with the other SDKs. For example,  the .NET and Java SDK’s can work with the same data within the same bucket without causing transcoding issues.

What’s in this release?

This release includes all of the features added in Developer Previews 1, 2 and 3 and Beta’s 1 and 2:

In addition to all of that, it adds the following features:

  • Replica Read Support
  • Support for GetL, Unlock and GetWithLock
  • Overloads for Prepend/Append that accepts byte arrays
  • Improvements to the View API that make serializing to and from POCOs easier

Most importantly, it includes a long list of bug fixes and improvements aimed at stabilizing the core and preparing it for production use.

Replica Reads

Replica Reads allow for reads against one or more replicas if your bucket is configured to support replicas. This is a useful for scenarios where the cluster is in an unhealthy state – for instance,  a node is down and it has not yet been failed over.

using (var cluster = new Cluster(config))
using (var bucket = cluster.OpenBucket())
const string key = “ReplicaKey”;

var result = bucket.GetFromReplica<string>(key);

In the code above, were simply replacing the usual Get(key) method, which retrieves the key directly from the primary, with the GetFromReplica(key) method, which will attempt to retrieve the key from one or more replicas. Note that Couchbase Server supports up to  three replicas and the number of nodes in your cluster must match the number of replicas (or copies) you wish to store.

GetL, Unlock and GetWithLock

GetL is the memcached command for locking a key for exclusive use. By default, the server will lock a key for 15 seconds and up to a maximum of 30 seconds. In the SDK, we provide a method called GetWithLock which encapsulates this behavior. The UnLock method allows for explicit removal of a lock on a key, before the expiration expires or when the server unlocks the key once the maximum expiry of the 30 seconds has been reached.

using (var bucket = _cluster.OpenBucket())
var key = “When_Key_Is_Locked_Mutate_Succeeds_If_Unlocked”;
Assert.IsTrue(bucket.Upsert(key, “{‘name’:’value’}”).Success);

var getl = bucket.GetWithLock<string>(key, 15);
Assert.IsTrue(getl.Success); //will succeed

var unlock = bucket.Unlock(key, getl.Cas);

var upsert = bucket.Upsert(key, “{‘name’:’value2′}”);

In the example above, we insert or update a key using the Upsert method, then lock the key for 15 seconds, before unlocking it and finally performing another mutation on it. If we had not used the Unlock method, the final Upsert method would have failed with a “KeyExists” status.

View Improvements

The View API has been improved to make it easier to use POCO (plain ole’ csharp objects) as the target of a view request.

using (var bucket = _cluster.OpenBucket(“beer-sample”))
var query = bucket.CreateQuery(“beer”, “all_beers”).Limit(10);
var result = bucket.Query<Beer>(query);

foreach (var beer in result.Values)
Console.WriteLine(“{0} has {1} abv.”, beer.Name, beer.Abv);

And the output:
21A IPA has 7.2 abv.
563 Stout has 5 abv.
Amendment Pale Ale has 5.2 abv.
Bitter American has 3.6 abv.
Double Trouble IPA has 9.8 abv.
General Pippo‘s Porter has 5.5 abv.
North Star Red has 5.8 abv.
Oyster Point Oyster Stout has 5.9 abv.
Potrero ESB has 5.2 abv.
South Park Blonde has 5 abv.

The big difference is that the results of the view, the value portion, will be serialized into a list with the value hydrating the POCO. Note that the id and key field is ignored in this list, however their is still a Rows property available that allows you to get this information.

What’s Changed?

While we have tried to keep from breaking any interfaces already published in the previous Beta release, there are a couple of changes that were made because they make for a better final API:

  • The IDocumentResult interface and implementations have changed: the Value property has been renamed to Content. This was done to make it more consistent with the Java SDK. Note that the return value for the non-document methods is still Value.
  • The ICluster interface has been made public (from internal) so that it’s easier to mock and test against

What’s not in this release?

The major missing feature is support for asynchronous operations using the TAP (Task Asynchrony Pattern) keywords async and await. This feature is in progress, but is simply not ready for prime time. Expect something later this year or early next.

How to get it?

Like all releases, the GA is available from NuGet as a package, as a direct download of the binaries from S3, and the source, as always, is available on GitHub:

  • Binaries are here.
  • The repo is here.
  • The NuGet packages are here.


Posted by Jeff Morris, Senior Software Engineer, Couchbase

Jeff Morris is a Senior Software Engineer at Couchbase. Prior to joining Couchbase, Jeff spent six years at Source Interlink as an Enterprise Web Architect. Jeff is responsible for the development of Couchbase SDKs and how to integrate with N1QL (query language).

One Comment

Leave a reply