Skip to content

Instantly share code, notes, and snippets.

@ToJans
Created April 14, 2012 19:36
Show Gist options
  • Save ToJans/2387354 to your computer and use it in GitHub Desktop.
Save ToJans/2387354 to your computer and use it in GitHub Desktop.
Problem with couchbase
using System;
using System.Linq;
using CouchBasePerf.Domain;
using Enyim.Caching.Memcached;
namespace CouchBasePerf.Handlers
{
public class HandlerBase
{
protected Couchbase.CouchbaseClient client = new Couchbase.CouchbaseClient();
protected void HandleConcurrent<T>(string Id, Action<T> Change) where T : AR, new()
{
CasResult<bool> casResult = new CasResult<bool>();
do
{
var cas = client.GetWithCas<T>(Id);
var instance = cas.Result ?? new T { Id = Id };
Change(instance);
if (instance.Changes.Any())
{
if (cas.Result == null)
// this keeps returning false ?
casResult.Result = client.Store(StoreMode.Add, Id, instance);
else
casResult = client.Cas(StoreMode.Set, Id, instance, cas.Cas);
}
else
{
casResult.Result = true;
}
} while (casResult.Result == false);
}
public void Execute<T>(T cmd)
{
(this as dynamic).Handle(cmd);
}
}
}
@ToJans
Copy link
Author

ToJans commented Apr 14, 2012

StoreMode.Add keeps returning false forever... what's wrong here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment