public void Set(string key, string value, ulong cas)
        {
            var casRes = Client.Cas(Enyim.Caching.Memcached.StoreMode.Replace, key, value, cas);

            if (casRes.Result == false)
            {
                throw new CASException("CAS expired");
            }
        }
Esempio n. 2
0
        public static CasResult <bool> CasJson(this CouchbaseClient client, StoreMode storeMode, string key, object value)
        {
            var json = JsonConvert.SerializeObject(value,
                                                   Formatting.None,
                                                   new JsonSerializerSettings {
                ContractResolver = new DocumentIdContractResolver()
            });

            return(client.Cas(storeMode, key, json));
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            CouchbaseClientConfiguration cbcc = new CouchbaseClientConfiguration();
            //设置各种超时时间   
            cbcc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 2);
            cbcc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 4);
            cbcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10);

            //使用默认的数据库   
            cbcc.Urls.Add(new Uri("http://127.0.0.1:8091/pools/default"));

            //建立一个Client,装入Client的配置   
            CouchbaseClient client = new CouchbaseClient(cbcc);

            //添加一条数据 
            CasResult<bool> casResult = client.Cas(StoreMode.Add, "Test", "Hello World!");
            //获取刚添加的数据   
            Console.WriteLine(client.Get("Test"));
            Console.WriteLine("完成!");
            Console.ReadLine();
        }