Created
April 14, 2012 19:36
-
-
Save ToJans/2387354 to your computer and use it in GitHub Desktop.
Problem with couchbase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
StoreMode.Add keeps returning false forever... what's wrong here ?