Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: .NET (C#) 1.1
Community Wiki and Resources
Wiki: .NET Client Library
Download Client Library
.NET Client Library
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
6 Retrieve Operations
Chapter Sections
Chapters

6.1. Get Methods

The Get() methods allow for direct access to a given key/value pair.

API Callobject.Get(key)
Asynchronousno
Description Get one or more key values
ReturnsObject ( Binary object )
Arguments 
string key Document ID used to identify the value
var beer = client.Get("beer") as Beer;

The generic form of the Get method allows for retrieval without the need to cast. If the stored type cannot be serialized to the generic type provided, an InvalidCastException will be thrown.

var beer = client.Get<Beer>("beer");
API Callobject.ExecuteGet(key)
Asynchronousno
Description Get one or more key values
ReturnsIGetOperationResult ( Get operation result )
Arguments 
string key Document ID used to identify the value

ExecuteGet() behaves as does Get() but returns an instance of an IGetOperationResult instead of directly returning the item for the key.

Beer beer = null;
var getResult = client.ExecuteGet("beer") as Beer;
if (getResult.Success && getResult.HasValue) {
	beer = getResult.Value as Beer;
} else {
	logger.Error(getResult.Message, getResult.Exception);
}

ExecuteGet() also has a generic form to allow an item to be retrieved without casting.

var beer = client.ExecuteGet<Beer>("beer").Value;
API Callobject.GetWithCas(key)
Asynchronousno
Description Get one or more key values
ReturnsCasResult<ulong> ( Cas result of bool )
Arguments 
string key Document ID used to identify the value

GetWithCas() will return a CasResult with the Cas value for a given key.

var casResult = client.GetWithCas("beer");
var beer = casResult.Result;
beer = "Heady Topper";
var storeResult = client.Cas(StoreMode.Replace, "beer", beer, casResult.Cas);
API Callobject.Get(keyarray)
Asynchronousno
Description Get one or more key values
ReturnsObject ( Binary object )
Arguments 
List <string> keyarray Array of keys used to reference one or more values.

Calling Get() with multiple keys returns a dictionary with the associated values.

client.Store(StoreMode.Set, "brewer", "Cottrell Brewing Co.");
client.Store(StoreMode.Set, "beer", "Old Yankee Ale");

var dict = client.Get(new string[] { "brewer", "beer" });
Console.WriteLine(dict["brewer"]);
Console.WriteLine(dict["beer"]);
API Callobject.ExecuteGet(keyarray)
Asynchronousno
Description Get one or more key values
ReturnsIGetOperationResult ( Get operation result )
Arguments 
List <string> keyarray Array of keys used to reference one or more values.

Calling ExecuteGet() with multiple keys returns a dictionary where the values are instances of an IGetOperationResult.

client.Store(StoreMode.Set, "brewer", "Cottrell Brewing Co.");
client.Store(StoreMode.Set, "beer", "Old Yankee Ale");

var dict = client.ExecuteGet(new string[] { "brewer", "beer" });
Console.WriteLine(dict["brewer"].Value);
Console.WriteLine(dict["beer"].Value);
API Callobject.Get(key, expiry)
Asynchronousno
Description Get a value and update the expiration time for a given key
Returns(none)
Arguments 
string key Document ID used to identify the value
object expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).

Calling the Get() method with a key and a new expiration value will cause get and touch operations to be performed.

var val = client.Get("beer", DateTime.Now.AddMinutes(5));
API Callobject.ExecuteGet(key, expiry)
Asynchronousno
Description Get a value and update the expiration time for a given key
ReturnsIGetOperationResult ( Get operation result )
Arguments 
string key Document ID used to identify the value
object expiry Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch).

ExecuteGet() when called with an expiration will update the time to live for an item and return an instane of an IGetOperationResult

var val = client.Get("beer", DateTime.Now.AddMinutes(5));