コード例 #1
0
ファイル: CacheBus.cs プロジェクト: hackerlank/trunk-chatbot
        public string dequeue_uniq(string QID)
        {
            if (m_client == null)
            {
                return("");
            }
            string headkey = QID + "_head";
            string tailkey = QID + "_tail";
            string message;

            ulong tail = m_client.Increment(tailkey, (ulong)0, (ulong)0);
            ulong head = m_client.Increment(headkey, (ulong)0, (ulong)1);

            if (head <= tail)
            {
                string key = string.Format("{0}:{1}", QID, head);
                message = m_client.Get <string>(key);
            }
            else
            {
                head    = m_client.Decrement(headkey, (ulong)0, (ulong)1);
                message = "";
            }

            return(message);
        }
コード例 #2
0
        public void DecrementTest()
        {
            MemcachedClient mc = new MemcachedClient();
            mc.Store(StoreMode.Set, "VALUE", "100");

            Assert.AreEqual(98L, mc.Decrement("VALUE", 2));
            Assert.AreEqual(88L, mc.Decrement("VALUE", 10));
        }
コード例 #3
0
        public void DecrementTest()
        {
            MemcachedClient mc = new MemcachedClient();

            mc.Store(StoreMode.Set, "VALUE", "100");

            Assert.AreEqual(98L, mc.Decrement("VALUE", 2));
            Assert.AreEqual(88L, mc.Decrement("VALUE", 10));
        }
コード例 #4
0
        public void DecrementTest()
        {
            using (MemcachedClient client = GetClient())
            {
                Assert.AreEqual(100, client.Decrement("VALUE", 100, 2), "Non-exsiting value should be set to default");
                Assert.AreEqual(76, client.Decrement("VALUE", 10, 24));

                Assert.AreEqual(0, client.Decrement("VALUE", 100, 1000), "Decrement should stop at 0");
            }
        }
コード例 #5
0
        public void DecrementTest()
        {
            using (MemcachedClient client = GetClient(MemcachedProtocol.Text))
            {
                client.Store(StoreMode.Set, "VALUE", "100");

                Assert.Equal((ulong)98, client.Decrement("VALUE", 0, 2));
                Assert.Equal((ulong)88, client.Decrement("VALUE", 0, 10));
            }
        }
コード例 #6
0
        public void DecrementTest()
        {
            using (MemcachedClient client = GetClient())
            {
                Assert.Equal((ulong)100, client.Decrement("VALUE", 100, 2));
                Assert.Equal((ulong)76, client.Decrement("VALUE", 10, 24));

                Assert.Equal((ulong)0, client.Decrement("VALUE", 100, 1000));
            }
        }
コード例 #7
0
        public void DecrementTest()
        {
            using (MemcachedClient client = GetClient())
            {
                client.Store(StoreMode.Set, "VALUE", "100");

                Assert.AreEqual(98L, client.Decrement("VALUE", 0, 2));
                Assert.AreEqual(88L, client.Decrement("VALUE", 0, 10));
            }
        }
コード例 #8
0
ファイル: operate.aspx.cs プロジェクト: mayleng/web
    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>");
        }
    }
コード例 #9
0
        public void TestDecrement()
        {
            MemcachedClient mc = new MemcachedClient();

            mc.Decrement("number", 19, 123);
            HandleLogs("[Cmd=Decrement]Decrement的值是:" + mc.GetCounter("number").ToString());
            mc.Delete("number");
        }
コード例 #10
0
        //test Decrement test
        public void DecrementTest()
        {
            MemcachedClient client = GetClient();

            client.Store(StoreMode.Set, "VALUE", "100");
            client.Decrement("VALUE", 0, 50);
            HandleLogs("[Cmd=Decrement]VALUE:" + client.Get("VALUE").ToString());
        }
コード例 #11
0
ファイル: BeITMemcached.aspx.cs プロジェクト: mayleng/web
        //6.Decrement the counter test
        public void DecrementTest()
        {
            MemcachedClient cache   = MemcachedClient.GetInstance("BeITMemcached");
            ulong?          counter = cache.Decrement("mycounter", 9000);

            if (counter.HasValue)
            {
                HandleLogs("[Cmd=Decrement]mycounter:" + counter.Value.ToString());
            }
        }
コード例 #12
0
ファイル: UnitTests.cs プロジェクト: DreamALittle/C-AccMVC
		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"));
		}
コード例 #13
0
        //减一
        protected void Button7_Click(object sender, EventArgs e)
        {
            ulong result = (ulong)client.Decrement("a", 1);

            Response.Write("<script>alert('" + result + "')</script>");
        }
コード例 #14
0
ファイル: MemcacheHelper.cs プロジェクト: shi-tou/MyMemcached
 /// <summary>
 ///  减小一个数值元素的值,减小多少由参数offset决定。 如果元素的值不是数值,以0值对待。如果减小后的值小于0,则新的值被设置为0
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="inc">增长幅度</param>
 /// <returns></returns>
 public static long DecrementFrom(string server, string key, long inc)
 {
     MemcachedClient client = GetClient(server);
     client.PoolName = server;
     return client.Decrement(key, inc);
 }
コード例 #15
0
 public long Decrement(string key, uint amount)
 {
     return(Execute(() => (long)_client.Decrement(key, 0, amount)));
 }
コード例 #16
0
 /// <summary>
 /// 减小一个数值元素的值,减小多少由参数offset决定。 如果元素的值不是数值,以0值对待。如果减小后的值小于0,则新的值被设置为0
 /// </summary>
 /// <param name="key">键</param>
 /// <returns></returns>
 public static long Decrement(string key)
 {
     return(mc.Decrement(key));
 }
コード例 #17
0
        /// <summary>
        ///  减小一个数值元素的值,减小多少由参数offset决定。 如果元素的值不是数值,以0值对待。如果减小后的值小于0,则新的值被设置为0
        /// </summary>
        /// <param name="server"></param>
        /// <param name="key">键</param>
        /// <param name="inc">增长幅度</param>
        /// <param name="hashCode">哈希码</param>
        /// <returns></returns>
        public static long DecrementFrom(string server, string key, long inc, int hashCode)
        {
            MemcachedClient client = GetClient(server);

            return(client.Decrement(key, inc, hashCode));
        }
コード例 #18
0
        /// <summary>
        /// 减小一个数值元素的值,减小多少由参数offset决定。 如果元素的值不是数值,以0值对待。如果减小后的值小于0,则新的值被设置为0
        /// </summary>
        /// <param name="server"></param>
        /// <param name="key">键</param>
        /// <returns></returns>
        public static long DecrementFrom(string server, string key)
        {
            MemcachedClient client = GetClient(server);

            return(client.Decrement(key));
        }
コード例 #19
0
        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"));
        }
コード例 #20
0
ファイル: CacheProvider.cs プロジェクト: Violet-Liu/Learn
 public static long Decrement(string key, uint amount)
 {
     return(mc.Decrement(key, amount));
 }
コード例 #21
0
 public ulong Decrement(string key, ulong defaultValue, ulong delta)
 {
     return(_client.Decrement(key, defaultValue, delta));
 }
コード例 #22
0
 /// <summary>
 /// 累减计数器
 /// </summary>
 /// <param name="strKey">键</param>
 /// <param name="ulongCount">累减值</param>
 /// <returns></returns>
 public static ulong?Decrement(string strKey, ulong ulongCount)
 {
     return(cache.Decrement(strKey, ulongCount));
 }
コード例 #23
0
 public long Decrement(string key)
 {
     return(m_memcachedClientIns.Decrement(key));
 }
コード例 #24
0
 public long Decrement(string key, uint amount)
 {
     return(Execute <long>(() => (long)_client.Decrement(key, 0uL, (ulong)amount)));
 }
コード例 #25
0
ファイル: Program.cs プロジェクト: Bogatinov/memcached
        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();
        }
コード例 #26
0
ファイル: Program.cs プロジェクト: gyb333/Learning
        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));
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: gyb333/Learning
        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));
        }