本文整理汇总了C#中MemcachedClient.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# MemcachedClient.Remove方法的具体用法?C# MemcachedClient.Remove怎么用?C# MemcachedClient.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemcachedClient
的用法示例。
在下文中一共展示了MemcachedClient.Remove方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MemcachedContainerStrategy
static MemcachedContainerStrategy()
{
// //初始化memcache服务器池
//SockIOPool pool = SockIOPool.GetInstance();
////设置Memcache池连接点服务器端。
//pool.SetServers(serverlist);
////其他参数根据需要进行配置
//pool.InitConnections = 3;
//pool.MinConnections = 3;
//pool.MaxConnections = 5;
//pool.SocketConnectTimeout = 1000;
//pool.SocketTimeout = 3000;
//pool.MaintenanceSleep = 30;
//pool.Failover = true;
//pool.Nagle = false;
//pool.Initialize();
//cache = new MemcachedClient();
//cache.EnableCompression = false;
try
{
//config.Authentication.Type = typeof(PlainTextAuthenticator);
//config.Authentication.Parameters["userName"] = "username";
//config.Authentication.Parameters["password"] = "password";
//config.Authentication.Parameters["zone"] = "zone";//domain? ——Jeffrey 2015.10.20
DateTime dt1 = DateTime.Now;
var config = GetMemcachedClientConfiguration();
var cache = new MemcachedClient(config);
var testKey = Guid.NewGuid().ToString();
var testValue = Guid.NewGuid().ToString();
cache.Store(StoreMode.Set, testKey, testValue);
var storeValue = cache.Get(testKey);
if (storeValue as string != testValue)
{
throw new Exception("MemcachedStrategy失效,没有计入缓存!");
}
cache.Remove(testKey);
DateTime dt2 = DateTime.Now;
WeixinTrace.Log(string.Format("MemcachedStrategy正常启用,启动及测试耗时:{0}ms", (dt2 - dt1).TotalMilliseconds));
}
catch (Exception ex)
{
//TODO:记录是同日志
WeixinTrace.Log(string.Format("MemcachedStrategy静态构造函数异常:{0}", ex.Message));
}
}
示例2: AddSetReplaceTest
public void AddSetReplaceTest()
{
MemcachedClient mc = new MemcachedClient();
mc.Store(StoreMode.Set, "VALUE", "1");
Assert.AreEqual("1", mc.Get("VALUE"), "Store failed");
mc.Store(StoreMode.Add, "VALUE", "2");
Assert.AreEqual("1", mc.Get("VALUE"), "Item should not have been Added");
mc.Store(StoreMode.Replace, "VALUE", "4");
Assert.AreEqual("4", mc.Get("VALUE"), "Replace failed");
mc.Remove("VALUE");
mc.Store(StoreMode.Replace, "VALUE", "8");
Assert.IsNull(mc.Get("VALUE"), "Item should not have been Replaced");
mc.Remove("VALUE");
mc.Store(StoreMode.Add, "VALUE", "16");
Assert.AreEqual("16", mc.Get("VALUE"), "Add failed");
}
示例3: DelCache
/// <summary>
/// 删除缓存(如果键不存在,则返回false)
/// </summary>
/// <param name="key">键</param>
/// <returns>成功:true失败:false</returns>
public static bool DelCache(string key)
{
using (MemcachedClient mc = new MemcachedClient())
{
return mc.Remove(key);
}
}
示例4: RemoveFromMC
private ErrorTypes RemoveFromMC(string sKey)
{
ErrorTypes oError = ErrorTypes.NoError;
try
{
using (MemcachedClient oMc = new MemcachedClient(m_oMcConfig))
{
oMc.Remove(sKey);
}
}
catch
{
oError = ErrorTypes.TaskResult;
}
return oError;
}
示例5: DeleteObjectTest
public void DeleteObjectTest()
{
MemcachedClient mc = new MemcachedClient();
mc.Remove(TestObjectKey);
Assert.IsNull(mc.Get(TestObjectKey), "Remove failed.");
}
示例6: Main
static void Main(string[] args)
{
//using (var client = new MemcachedClient())
//{
// client.Store(StoreMode.Set, "currentTime", DateTime.UtcNow.ToString());
// string value = client.Get<string>("currentTime");
// Console.WriteLine(client.Stats());
// Console.WriteLine(value);
// Console.ReadKey();
//}
// create a MemcachedClient
// in your application you can cache the client in a static variable or just recreate it every time
// MemcachedClient mc = new MemcachedClient();
// you can create another client using a different section from your app/web.config
// this client instance can have different pool settings, key transformer, etc.
// MemcachedClient mc2 = new MemcachedClient("memcached");
// or just initialize the client from code
MemcachedClientConfiguration config = new MemcachedClientConfiguration();
config.Servers.Add(new IPEndPoint(IPAddress.Loopback, 11211));
config.Protocol = MemcachedProtocol.Binary;
var mc = new MemcachedClient();
for (var i = 0; i < 100; i++)
mc.Store(StoreMode.Set, "Hello", "World");
var myHello = mc.Get("Hello");
Console.WriteLine(myHello);
// simple multiget; please note that only 1.2.4 supports it (windows version is at 1.2.1)
List<string> keys = new List<string>();
for (int i = 1; i < 100; i++)
{
string k = "aaaa" + i + "--" + (i * 2);
keys.Add(k);
mc.Store(StoreMode.Set, k, i);
}
IDictionary<string, ulong> cas;
IDictionary<string, object> retvals = mc.Get(keys);
List<string> keys2 = new List<string>(keys);
keys2.RemoveRange(0, 50);
IDictionary<string, object> retvals2 = mc.Get(keys2);
retvals2 = mc.Get(keys2);
ServerStats ms = mc.Stats();
// store a string in the cache
mc.Store(StoreMode.Set, "MyKey", "Hello World");
// retrieve the item from the cache
Console.WriteLine("MyKey: {0}", mc.Get("MyKey"));
Console.WriteLine("Increment num1 by 10 {0}", mc.Increment("num1", 1, 10));
Console.WriteLine("Increment num1 by 10 {0}", mc.Increment("num1", 1, 10));
Console.WriteLine("Increment num1 by 14 {0}", mc.Decrement("num1", 1, 14));
//// store some other items
mc.Store(StoreMode.Set, "D1", 1234L);
mc.Store(StoreMode.Set, "D2", DateTime.Now);
mc.Store(StoreMode.Set, "D3", true);
mc.Store(StoreMode.Set, "D4", new Product());
mc.Store(StoreMode.Set, "D5", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
mc.Store(StoreMode.Set, "D1", 1234L);
mc.Store(StoreMode.Set, "D2", DateTime.Now);
mc.Store(StoreMode.Set, "D3", true);
mc.Store(StoreMode.Set, "D4", new Product());
Console.WriteLine("D1: {0}", mc.Get("D1"));
Console.WriteLine("D2: {0}", mc.Get("D2"));
Console.WriteLine("D3: {0}", mc.Get("D3"));
Console.WriteLine("D4: {0}", mc.Get("D4"));
Console.WriteLine("D5: {0}", System.Text.Encoding.UTF8.GetString(mc.Get<byte[]>("D5")));
Console.WriteLine("Removing D1-D4");
// delete them from the cache
mc.Remove("D1");
mc.Remove("D2");
mc.Remove("D3");
mc.Remove("D4");
//ServerStats stats = mc.Stats();
Console.WriteLine("Active Connections: {0}",ms.GetValue(ServerStats.All, StatItem.ConnectionCount));
Console.WriteLine("GET operations {0}", ms.GetValue(ServerStats.All, StatItem.GetCount));
//// add an item which is valid for 10 mins
mc.Store(StoreMode.Set, "D4", new Product(), new TimeSpan(0, 10, 0));
Console.WriteLine(mc.Stats().GetValue(new IPEndPoint(IPAddress.Loopback, 11211), StatItem.BytesRead));
Console.ReadLine();
}
示例7: Main
static void Main(string[] args)
{
// create a MemcachedClient
// in your application you can cache the client in a static variable or just recreate it every time
MemcachedClient mc = new MemcachedClient();
mc.Get("");
// you can create another client using a different section from your app/web.config
// this client instance can have different pool settings, key transformer, etc.
// MemcachedClient mc2 = new MemcachedClient("memcached");
// or just initialize the client from code
//
// MemcachedClientConfiguration config = new MemcachedClientConfiguration();
// config.Servers.Add(new IPEndPoint(IPAddress.Loopback, 20002));
//
// MemcachedClient mc = new MemcachedClient(config);
// simple multiget; please note that only 1.2.4 supports it (windows version is at 1.2.1)
//List<string> keys = new List<string>();
//for (int i = 1; i < 100; i++)
//{
// string k = "aaaa" + i + "--" + (i * 2);
// keys.Add(k);
// mc.Store(StoreMode.Set, k, i);
//}
//IDictionary<string, ulong> cas;
//IDictionary<string, object> retvals = mc.Get(keys, out cas);
//List<string> keys2 = new List<string>(keys);
//keys2.RemoveRange(0, 50);
//IDictionary<string, object> retvals2 = mc.Get(keys2, out cas);
//retvals2 = mc.Get(keys2, out cas);
//ServerStats ms = mc.Stats();
// store a string in the cache
mc.Store(StoreMode.Set, "MyKey", "Hello World");
// retrieve the item from the cache
Console.WriteLine(mc.Get("MyKey"));
// store some other items
mc.Store(StoreMode.Set, "D1", 1234L);
mc.Store(StoreMode.Set, "D2", DateTime.Now);
mc.Store(StoreMode.Set, "D3", true);
mc.Store(StoreMode.Set, "D4", new Product());
mc.Store(StoreMode.Set, "D5", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
//mc2.Store(StoreMode.Set, "D1", 1234L);
//mc2.Store(StoreMode.Set, "D2", DateTime.Now);
//mc2.Store(StoreMode.Set, "D3", true);
//mc2.Store(StoreMode.Set, "D4", new Product());
Console.WriteLine("D1: {0}", mc.Get("D1"));
Console.WriteLine("D2: {0}", mc.Get("D2"));
Console.WriteLine("D3: {0}", mc.Get("D3"));
Console.WriteLine("D4: {0}", mc.Get("D4"));
byte[] tmp = mc.Get<byte[]>("D5");
// delete them from the cache
mc.Remove("D1");
mc.Remove("D2");
mc.Remove("D3");
mc.Remove("D4");
ServerStats stats = mc.Stats();
Console.WriteLine(stats.GetValue(ServerStats.All, StatItem.ConnectionCount));
Console.WriteLine(stats.GetValue(ServerStats.All, StatItem.GetCount));
// add an item which is valid for 10 mins
mc.Store(StoreMode.Set, "D4", new Product(), new TimeSpan(0, 10, 0));
Console.ReadLine();
}
示例8: test
public static void test()
{
MemcachedClientConfiguration config = new MemcachedClientConfiguration();
config.Servers.Add(new IPEndPoint(IPAddress.Loopback, 11211));
config.Protocol = MemcachedProtocol.Binary;
//config.Authentication.Type = typeof(PlainTextAuthenticator);
//config.Authentication.Parameters["userName"] = "demo";
//config.Authentication.Parameters["password"] = "demo";
var mc = new MemcachedClient(config);
for (var i = 0; i < 100; i++)
mc.Store(StoreMode.Set, "Hello", "World");
// simple multiget; please note that only 1.2.4 supports it (windows version is at 1.2.1)
List<string> keys = new List<string>();
for (int i = 1; i < 100; i++)
{
string k = "aaaa" + i + "--" + (i * 2);
keys.Add(k);
mc.Store(StoreMode.Set, k, i);
}
IDictionary<string, ulong> cas;
IDictionary<string, object> retvals = mc.Get(keys);
List<string> keys2 = new List<string>(keys);
keys2.RemoveRange(0, 50);
IDictionary<string, object> retvals2 = mc.Get(keys2);
retvals2 = mc.Get(keys2);
ServerStats ms = mc.Stats();
// store a string in the cache
mc.Store(StoreMode.Set, "MyKey", "Hello World");
// retrieve the item from the cache
Console.WriteLine(mc.Get("MyKey"));
Console.WriteLine(mc.Increment("num1", 1, 10));
Console.WriteLine(mc.Increment("num1", 1, 10));
Console.WriteLine(mc.Decrement("num1", 1, 14));
// store some other items
mc.Store(StoreMode.Set, "D1", 1234L);
mc.Store(StoreMode.Set, "D2", DateTime.Now);
mc.Store(StoreMode.Set, "D3", true);
mc.Store(StoreMode.Set, "D4", new Person());
mc.Store(StoreMode.Set, "D5", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
//mc2.Store(StoreMode.Set, "D1", 1234L);
//mc2.Store(StoreMode.Set, "D2", DateTime.Now);
//mc2.Store(StoreMode.Set, "D3", true);
//mc2.Store(StoreMode.Set, "D4", new Product());
Console.WriteLine("D1: {0}", mc.Get("D1"));
Console.WriteLine("D2: {0}", mc.Get("D2"));
Console.WriteLine("D3: {0}", mc.Get("D3"));
Console.WriteLine("D4: {0}", mc.Get("D4"));
byte[] tmp = mc.Get<byte[]>("D5");
// delete them from the cache
mc.Remove("D1");
mc.Remove("D2");
mc.Remove("D3");
mc.Remove("D4");
ServerStats stats = mc.Stats();
Console.WriteLine(stats.GetValue(ServerStats.All, StatItem.ConnectionCount));
Console.WriteLine(stats.GetValue(ServerStats.All, StatItem.GetCount));
// add an item which is valid for 10 mins
mc.Store(StoreMode.Set, "D4", new Person(), new TimeSpan(0, 10, 0));
}
示例9: Delete_Study
public void Delete_Study()
{
using (var client = new MemcachedClient())
{
// 没有键,返回false。
var result1 = client.Remove("userid");
Assert.False(result1);
client.Store(StoreMode.Set, "userid", "123456");
var result2 = client.Remove("userid");
Assert.True(result2);
client.FlushAll();
}
}