//7.Delete test public void DeleteTest() { MemcachedClient cache = MemcachedClient.GetInstance("BeITMemcached"); cache.Delete("castest"); HandleLogs("[Cmd=Delete]castest:" + cache.CheckAndSet("castest", "a", 0)); }
//3.CheckAndSet test public void CheckAndSetTest() { MemcachedClient cache = MemcachedClient.GetInstance("BeITMemcached"); cache.Set("castest", "a"); //Trying to CAS key castest with the wrong unique HandleLogs("[Cmd=CheckAndSet]castest:" + cache.CheckAndSet("castest", "a", 0)); }
private ulong GetIncreasedIndex(string index_key) { ulong?index = null; while (index == null) { bool r = m_Client.Add(index_key, 0); if (r) { index = 0; } else { //index = m_Client.Increment(en_index_key, 1); MemcachedClient.CasResult casRst; ulong unique; do { object t = m_Client.Gets(index_key, out unique); if (t == null) { index = null; break; } index = Convert.ToUInt64(t); if (index >= MAX_LENGTH) { index = 0; } else { index = index + 1; } casRst = m_Client.CheckAndSet(index_key, index.Value, unique); } while (casRst != MemcachedClient.CasResult.Stored); } } return(index.Value); }
public bool ContainsKey(string key) { return(memcachedClient.CheckAndSet(key, new object(), 1)); }
public static bool CheckAndSet(string key, object value, ulong cas) { return(mc.CheckAndSet(key, value, cas)); }
/// <summary> /// 验证版本号并设置缓存,指定版本不是最新版本,则不设置缓存 /// </summary> /// <param name="strKey">缓存键</param> /// <param name="objValue">缓存值</param> /// <param name="ulongNique">版本号</param> /// <returns></returns> public static string CheckAndSet(string strKey, object objValue, ulong ulongNique) { return(cache.CheckAndSet(strKey, objValue, ulongNique)); }