本文整理汇总了C#中MemcachedClient.Cas方法的典型用法代码示例。如果您正苦于以下问题:C# MemcachedClient.Cas方法的具体用法?C# MemcachedClient.Cas怎么用?C# MemcachedClient.Cas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemcachedClient
的用法示例。
在下文中一共展示了MemcachedClient.Cas方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddToMCWithCas
private ErrorTypes AddToMCWithCas(string sKey, TaskResultData oTast, ulong cas)
{
ErrorTypes oError = ErrorTypes.NoError;
try
{
using (MemcachedClient oMc = new MemcachedClient(m_oMcConfig))
{
string sDataToStore = null;
XmlSerializer oXmlSerializer = new XmlSerializer(typeof(TaskResultData));
using (StringWriter oStringWriter = new StringWriter())
{
oXmlSerializer.Serialize(oStringWriter, oTast);
sDataToStore = oStringWriter.ToString();
}
if (cas != 0)
oMc.Cas(StoreMode.Set, sKey, sDataToStore, m_oTtl, cas);
else
oMc.Store(StoreMode.Set, sKey, sDataToStore, m_oTtl);
}
}
catch
{
oError = ErrorTypes.TaskResult;
}
return oError;
}
示例2: Cas_Study
public void Cas_Study()
{
using (var client = new MemcachedClient())
{
/*
* 非常重要的CAS操作
*/
client.Store(StoreMode.Set, "userid", "123456");
var result1 = client.GetWithCas("userid");
var result2 = client.Cas(StoreMode.Set, "userid", "6543321");
Assert.True(result2.Result);
var result3 = client.Cas(StoreMode.Set, "userid", "123456", result1.Cas);
Assert.False(result3.Result);
client.FlushAll();
}
}