The Decrement() methods reduce the value of a
given key if the corresponding value can be parsed to an integer
value. These operations are provided at a protocol level to
eliminate the need to get, update, and reset a simple integer
value in the database. All the .NET Client Library methods support
the use of an explicit offset value that will be used to reduce
the stored value in the database. Note that the
Decrement methods may not be used with keys
that were first created with a Store method. To
initialize a counter, you must first use either
Increment or Decrement with
a default value.
| API Call | object.Decrement(key, defaultvalue, offset) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | CasResult<ulong> (
Cas result of bool
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist.
client.Remove("inventory"); //reset the counter client.Decrement("inventory", 100, 1); //counter will be 100 client.Decrement("inventory", 100, 1); //counter will be 99
| API Call | object.Decrement(key, defaultvalue, offset, validfor) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | CasResult<ulong> (
Cas result of bool
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
TimeSpan validfor | Expiry time (in seconds) for key | ||
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist and set an expiry of 60 seconds.
client.Decrement("inventory", 100, 1, TimeSpan.FromSeconds(60));| API Call | object.Decrement(key, defaultvalue, offset, expiresat) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | CasResult<ulong> (
Cas result of bool
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
DateTime expiresat | Explicit expiry time for key | ||
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist and set an expiry of 5 minutes.
client.Decrement("inventory", 100, 1, DateTime.Now.AddMinutes(5));| API Call | object.Decrement(key, defaultvalue, offset, casunique) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | CasResult<ulong> (
Cas result of bool
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
ulong casunique | Unique value used to verify a key/value combination | ||
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist. Fail if CAS value doesn't match CAS value on server.
var result = client.ExecuteGet("inventory"); client.Decrement("inventory", 100, 1, result.Cas);
| API Call | object.Decrement(key, defaultvalue, offset, validfor, casunique) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | CasResult<ulong> (
Cas result of bool
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
TimeSpan validfor | Expiry time (in seconds) for key | ||
ulong casunique | Unique value used to verify a key/value combination | ||
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist and set an expiry of 60 seconds. Fail if CAS value doesn't match CAS value on server.
var result = client.ExecuteGet("inventory"); client.Decrement("inventory", 100, 1, TimeSpan.FromSeconds(60), result.Cas);
| API Call | object.Decrement(key, defaultvalue, offset, expiresat, casunique) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | CasResult<ulong> (
Cas result of bool
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
DateTime expiresat | Explicit expiry time for key | ||
ulong casunique | Unique value used to verify a key/value combination | ||
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist and set an expiry of 5 minutes. Fail if CAS value doesn't match CAS value on server.
var result = client.ExecuteGet("inventory"); client.Decrement("inventory", 100, 1, DateTime.Now.AddMinutes(5), result.Cas);
| API Call | object.ExecuteDecrement(key, defaultvalue, offset) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | IMutateOperationResult (
Mutate operation result
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
ExecuteDecrement will return an instance of an
IMutateOperationResult
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist.
client.Remove("inventory"); //reset the counter client.ExecuteDecrement("inventory", 100, 1); //counter will be 100 var result = client.ExecuteDecrement("inventory", 100, 1); //counter will be 99 if (! result.Success) { Console.WriteLine("Decrement failed with message {0} and status code {1}", result.Message, result.StatusCode); if (result.Exception != null) { throw result.Exception; } }
| API Call | object.ExecuteDecrement(key, defaultvalue, offset, validfor) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | IMutateOperationResult (
Mutate operation result
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
TimeSpan validfor | Expiry time (in seconds) for key | ||
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist and set an expiry of 60 seconds.
client.ExecuteDecrement("inventory", 100, 1, TimeSpan.FromSeconds(60));| API Call | object.ExecuteDecrement(key, defaultvalue, offset, expiresat) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | IMutateOperationResult (
Mutate operation result
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
DateTime expiresat | Explicit expiry time for key | ||
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist and set an expiry of 5 minutes.
client.ExecuteDecrement("inventory", 100, 1, DateTime.Now.AddMinutes(5));| API Call | object.ExecuteDecrement(key, defaultvalue, offset, casunique) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | IMutateOperationResult (
Mutate operation result
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
ulong casunique | Unique value used to verify a key/value combination | ||
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist. Fail if CAS value doesn't match CAS value on server.
var result = client.ExecuteGet("inventory"); client.ExecuteDecrement("inventory", 100, 1, result.Cas);
| API Call | object.ExecuteDecrement(key, defaultvalue, offset, validfor, casunique) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | IMutateOperationResult (
Mutate operation result
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
TimeSpan validfor | Expiry time (in seconds) for key | ||
ulong casunique | Unique value used to verify a key/value combination | ||
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist and set an expiry of 60 seconds. Fail if CAS value doesn't match CAS value on server.
var result = client.ExecuteGet("inventory"); client.ExecuteDecrement("inventory", 100, 1, TimeSpan.FromSeconds(60), result.Cas);
| API Call | object.ExecuteDecrement(key, defaultvalue, offset, expiresat, casunique) | ||
| Asynchronous | no | ||
| Description | Decrement the value of an existing numeric key. The Couchbase Server stores numbers as unsigned values. Therefore the lowest you can decrement is to zero. | ||
| Returns | IMutateOperationResult (
Mutate operation result
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object defaultvalue | Value to be stored if key does not already exist | ||
Integer offset | Integer offset value to increment/decrement (default 1) | ||
DateTime expiresat | Explicit expiry time for key | ||
ulong casunique | Unique value used to verify a key/value combination | ||
Decrement the inventory counter by 1, defaulting to 100 if the key doesn't exist and set an expiry of 5 minutes. Fail if CAS value doesn't match CAS value on server.
var result = client.ExecuteGet("inventory"); client.ExecuteDecrement("inventory", 100, 1, DateTime.Now.AddMinutes(5), result.Cas);