public void IncrementTest() { using (MemcachedClient client = GetClient()) { Assert.Equal((ulong)100, client.Increment("VALUE", 100, 2)); Assert.Equal((ulong)124, client.Increment("VALUE", 10, 24)); } }
public void IncrementTest() { using (MemcachedClient client = GetClient()) { Assert.AreEqual(100, client.Increment("VALUE", 100, 2), "Non-exsiting value should be set to default"); Assert.AreEqual(124, client.Increment("VALUE", 10, 24)); } }
public void IncrementTest() { MemcachedClient mc = new MemcachedClient(); mc.Store(StoreMode.Set, "VALUE", "100"); Assert.AreEqual(102L, mc.Increment("VALUE", 2)); Assert.AreEqual(112L, mc.Increment("VALUE", 10)); }
public void IncrementTest() { using (MemcachedClient client = GetClient()) { Assert.IsTrue(client.Store(StoreMode.Set, "VALUE", "100"), "Initialization failed"); Assert.AreEqual(102L, client.Increment("VALUE", 0, 2)); Assert.AreEqual(112L, client.Increment("VALUE", 0, 10)); } }
public void IncrementLongTest() { var initialValue = 56UL * (ulong)System.Math.Pow(10, 11) + 1234; using (MemcachedClient client = GetClient()) { Assert.AreEqual(initialValue, client.Increment("VALUE", initialValue, 2UL), "Non-existing value should be set to default"); Assert.AreEqual(initialValue + 24, client.Increment("VALUE", 10UL, 24UL)); } }
public void IncrementLongTest() { var initialValue = 56UL * (ulong)System.Math.Pow(10, 11) + 1234; using (MemcachedClient client = GetClient()) { Assert.Equal(initialValue, client.Increment("VALUE", initialValue, 2UL)); Assert.Equal(initialValue + 24, client.Increment("VALUE", 10UL, 24UL)); } }
public void IncrementTest() { using (MemcachedClient client = GetClient(MemcachedProtocol.Text)) { Assert.True(client.Store(StoreMode.Set, "VALUE", "100"), "Initialization failed"); Assert.Equal((ulong)102, client.Increment("VALUE", 0, 2)); Assert.Equal((ulong)112, client.Increment("VALUE", 0, 10)); } }
public static void test12() { long i = 0; mc.StoreCounter("foo", i); mc.Increment("foo"); // foo now == 1 mc.Increment("foo", (long)5); // foo now == 6 long j = mc.Decrement("foo", (long)2); // foo now == 4 Debug.Assert(j == 4); Debug.Assert(j == mc.GetCounter("foo")); }
public async Task IncrementNoDefaultTest() { using (MemcachedClient client = GetClient()) { Assert.Equal((ulong)2, client.Increment("VALUE", 2, 2)); Assert.Equal((ulong)4, client.Increment("VALUE", 2, 2)); var value = await client.GetValueAsync <string>("VALUE"); Assert.Equal("4", value); } }
public void TestGetCounter() { MemcachedClient mc = new MemcachedClient(); mc.Increment("number", 3, 123); HandleLogs("[Cmd=GetCounter]GetCounter的值是:" + mc.GetCounter("number").ToString()); }
protected void btnMemOperate(object sender, EventArgs e) { string myConn = ConfigurationManager.AppSettings["BeITMemcacheIP"].ToString(); MemcachedClientConfiguration config = new MemcachedClientConfiguration(); config.AddServer(myConn, 11211); config.Protocol = MemcachedProtocol.Binary; MemcachedClient client = new MemcachedClient(config); string keyval = key3.Text.Trim(); ulong number = ulong.Parse(num.Text.Trim()); string selflag = Select1.Value; ulong renum; if (selflag.Equals("+")) { renum = client.Increment(keyval, 10, number); Response.Write("<script>window.alert('" + renum + "');window.location.href='../Mem_RedisTest.aspx'</script>"); } else if (selflag.Equals("-")) { renum = client.Decrement(keyval, 10, number); Response.Write("<script>window.alert('" + renum + "');window.location.href='../Mem_RedisTest.aspx'</script>"); } }
public void TestIncrement() { MemcachedClient mc = new MemcachedClient(); //Test Increment mc.Increment("number", 7, 123); HandleLogs("[Cmd=Increment]Increment的值是:" + mc.GetCounter("number").ToString()); }
//test Increment Test public void IncrementTest() { MemcachedClient client = GetClient(); client.Store(StoreMode.Set, "VALUE", "100"); client.Increment("VALUE", 0, 2); HandleLogs("[Cmd=Increment]VALUE:" + client.Get("VALUE").ToString()); }
//5.Increment the counter test public void IncrementTest() { MemcachedClient cache = MemcachedClient.GetInstance("BeITMemcached"); ulong? counter = cache.Increment("mycounter", 1); if (counter.HasValue) { HandleLogs("[Cmd=Increment]mycounter:" + counter.Value.ToString()); } }
/// <summary> /// 缓存对象自增长 /// </summary> /// <param name="key">键</param> public ulong?Increment(string key, ulong value) { ulong?count = _mcClient.Increment(key, value); if (!count.HasValue) { count = value; this.SetCounter(key, value); } return(count.Value); }
public void IncrementNoDefaultTest() { using (MemcachedClient client = GetClient()) { Assert.IsNull(client.Get("VALUE"), "Initialization failed"); Assert.AreEqual(2, client.Increment("VALUE", 2, 2), "Increment failed"); var value = client.Get("VALUE"); Assert.AreEqual("2", value, "Get failed. Expected 2, returned: '" + value + "'"); } }
public override string Get(PrimaryKeyEntity entity) { MemcachedClient client = new MemcachedClient(); if (client.KeyExists(entity.Prefix)) { long id = client.Increment(entity.Prefix, 1); return(string.Format("{0}{1}", entity.IsMustPrefix ? entity.Prefix : string.Empty, entity.IsMustFillWithChar ? id.ToString().PadLeft(entity.NumberLength, entity.FillChar) : id.ToString())); } else { return(string.Empty); } }
public override string Get(PrimaryKeyEntity entity) { if (string.IsNullOrWhiteSpace(entity.Prefix)) { return(string.Empty); } long i = 0; MemcachedClient client = new MemcachedClient(); if (client.KeyExists(entity.Prefix)) { i = (long)client.Get(entity.Prefix); } i = client.Increment(entity.Prefix, 1); string id = string.Format("{0}{1}{2}", entity.IsMustPrefix ? entity.Prefix : string.Empty, DateTime.Now.ToString("yyyyMMdd"), entity.IsMustFillWithChar ? i.ToString().PadLeft(entity.NumberLength, entity.FillChar) : i.ToString()); return(id); }
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"] = "******"; //config.Authentication.Parameters["password"] = "******"; 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)); }
public long Increment(string key, uint amount) { return(Execute <long>(() => (long)_client.Increment(key, 0uL, (ulong)amount))); }
public void Clock_tick(object sender, EventArgs eArgs) { if (m_client == null) { return; } if (sender == m_clock) { // Check for messages Stack STK = new Stack(); foreach (string ourQueue in m_ourQueues.Keys) { STK.Push(ourQueue); } //foreach (string ourQueue in ourQueues.Keys) while (STK.Count > 0) { string ourQueue = (string)STK.Pop(); ulong headID = m_client.Increment(ourQueue, (ulong)0, (ulong)0); // null increment gets the value ulong lastQid = getLastReadID(ourQueue); // our internal count if (headID == lastQid) { continue; // we are up to date } processMessageHandler watcher = null; if (m_watchers.ContainsKey(ourQueue)) { watcher = (processMessageHandler)m_watchers[ourQueue]; } while (lastQid != headID) { string message = dequeue(ourQueue); if ((message == "") || (message == null)) { break; } // notify anybody interested if (watcher != null) { watcher(message); } lastQid = getLastReadID(ourQueue); // our internal count } } } }
public static void test1() { mc.Set("foo", true); bool b = (bool)mc.Get("foo"); Assert.AreEqual(b, true); mc.Set("foo", int.MaxValue); int i = (int)mc.Get("foo"); Assert.AreEqual(i, int.MaxValue); string input = "test of string encoding"; mc.Set("foo", input); string s = (string)mc.Get("foo"); Assert.IsTrue(s == input); int unique = 2; s = mc.Get("foo", unique).ToString(); Assert.IsTrue(s == input); mc.Set("foo", 'z'); char c = (char)mc.Get("foo"); Assert.IsTrue(c == 'z'); mc.Set("foo", (byte)127); byte b1 = (byte)mc.Get("foo"); Assert.IsTrue(b1 == 127); mc.Set("foo", new StringBuilder("hello")); StringBuilder o = (StringBuilder)mc.Get("foo"); Assert.IsTrue(o.ToString() == "hello"); mc.Set("foo", (short)100); short o1 = (short)mc.Get("foo"); Assert.IsTrue(o1 == 100); mc.Set("foo", long.MaxValue); long o2 = (long)mc.Get("foo"); Assert.IsTrue(o2 == long.MaxValue); mc.Set("foo", 1.1d); double o3 = (double)mc.Get("foo"); Assert.IsTrue(o3 == 1.1d); mc.Set("foo", 1.1f); float o4 = (float)mc.Get("foo"); Assert.IsTrue(o4 == 1.1f); mc.Delete("foo"); mc.Set("foo", 100, DateTime.Now); System.Threading.Thread.Sleep(1000); var o5 = mc.Get("foo"); Assert.IsTrue(o5 != null); long i1 = 0; mc.StoreCounter("foo", i1); mc.Increment("foo"); // foo now == 1 mc.Increment("foo", (long)5); // foo now == 6 long j = mc.Decrement("foo", (long)2); // foo now == 4 Assert.IsTrue(j == 4); Assert.IsTrue(j == mc.GetCounter("foo")); DateTime d1 = new DateTime(); mc.Set("foo", d1); DateTime d2 = (DateTime)mc.Get("foo"); Assert.IsTrue(d1 == d2); if (mc.KeyExists("foobar123")) { mc.Delete("foobar123"); } Assert.IsTrue(!mc.KeyExists("foobar123")); mc.Set("foobar123", 100000); Assert.IsTrue(mc.KeyExists("foobar123")); if (mc.KeyExists("counterTest123")) { mc.Delete("counterTest123"); } Assert.IsTrue(!mc.KeyExists("counterTest123")); mc.StoreCounter("counterTest123", 0); Assert.IsTrue(mc.KeyExists("counterTest123")); }
//加一 protected void Button6_Click(object sender, EventArgs e) { ulong result = (ulong)client.Increment("a", 1); Response.Write("<script>alert('" + result + "')</script>"); }
public long Increment(string key) { return(m_memcachedClientIns.Increment(key)); }
public long Increment(string key, uint amount) { return(Execute(() => (long)_client.Increment(key, 0, amount))); }
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(); }
/// <summary> /// 将一个数值元素增加。 如果元素的值不是数值类型,将其作为0处理 /// </summary> /// <param name="key">键</param> /// <returns></returns> public static long Increment(string key) { return(mc.Increment(key)); }
/// <summary> /// 将一个数值元素增加。 如果元素的值不是数值类型,将其作为0处理 /// </summary> /// <param name="server"></param> /// <param name="key">键</param> /// <param name="inc">增长幅度</param> /// <param name="hashCode">哈希码</param> /// <returns></returns> public static long IncrementTo(string server, string key, long inc, int hashCode) { MemcachedClient client = GetClient(server); return(client.Increment(key, inc, hashCode)); }
/// <summary> /// 将一个数值元素增加。 如果元素的值不是数值类型,将其作为0处理 /// </summary> /// <param name="server"></param> /// <param name="key">键</param> /// <returns></returns> public static long IncrementTo(string server, string key) { MemcachedClient client = GetClient(server); return(client.Increment(key)); }
public static long Increment(string key, uint amount) { return(mc.Increment(key, amount)); }
public ulong Increment(string key, ulong defaultValue, ulong delta) { return(_client.Increment(key, defaultValue, delta)); }
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"] = "******"; //config.Authentication.Parameters["password"] = "******"; 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)); }