Search:

Search all manuals
Search this manual
Manual
Getting Started with Membase and C#
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
3 Hello C# Membase
Chapter Sections
Chapters

3.1. Membase API overview

3.1.1. Memcached methods
3.1.2. Check And Set
3.1.3. Specialized Membase Methods

The Enyim Membase client library has many API methods that you can use to implement whatever you desire. The following tables outline some API categories, the methods that are available, and a short description of what those methods do.

3.1.1. Memcached methods

These methods allow all of the operations defined for the memcached protocol, which is implemented in the Enyim client library inside the Enyim.Caching.MemcachedClient class. A few of these methods have generic versions that allow automatic type casting of serializable objects to be retrieved. Many of these methods can also return a Boolean value indicating whether the operation succeeded or failed.

AppendAppend some bytes to the end of a key.
DecrementDecrement a key and return the value.
FlushAllFlush all data on all servers for the connected bucket.
GetGet the value for a key.
IncrementIncrement the value of a key.
PrependPrepend some bytes to the start of a key.
RemoveRemoves a key from the database.
StatsReturn statistics about a key, or about the servers in the cluster.
StoreStores a value for a key.
TryGetTries to get a value, and returns a Boolean if the value was successfully retrieved.

3.1.2. Check And Set

The MemcachedClient has a number of methods that allow a Check and Set operation to be performed on keys in the database. Check and Set operations (CAS) are a way to prevent data loss in a distributed database without heavy locks or transactions. Before you write data into the database you can obtain the current cas value, which is effectively like a version number for the data in the database. When you write your new data into the database you pass along the version you think the data is supposed to have. If, by the time the write happens, the value is no longer valid your code will be told that your write failed. You will then be able to take corrective action such as reading the new value, its cas, and retrying your operation.

CasPerform a Check And Set operation.
DecrementSome of the Decrement overloads support returning a CasResult.
GetWithCasPerform a Get and also return a CasResult.
IncrementSome Increment overloads support passing back a Cas to check for whether the operation succeeded.
TryGetWithCasReturns a Boolean so your code knows if the value exists or not, and returns a CasResult if it succeeds.

3.1.3. Specialized Membase Methods

The Enyim library includes the MembaseClient class, which is a subclass of the MemcachedClient class. It has a set of methods that provide very powerful ways to interact with data and extent the expiry time concurrently. You will be able to use all of these methods (get, touch and CAS equivalents) on both both Membase and Memcached buckets in Membase 1.7, except for the Sync operation. Sync is only supported on Membase buckets.

GetA special form of Get, sometimes referred to as Get and Touch, which a returns the value but allows the expiry time to be reset.
GetWithCasGet a value, its Cas, and also reset the expiry, all at once.
SyncA very new operation that allows you to wait for data in the database to change in specific ways. Allows you to know when data has been persisted, replicated, or mutated. Remember this operation can only be performed on Membase buckets.
TouchReset a keys expiry date without getting its value.
TryGetTry to get a value, a Boolean indicates success, reset the expiry, all at once.
TryGetWithCasSwiss army knife. Gets a Boolean indicating if the operation succeeded, gets a CasResult and also resets the expiry time of value.