Exemplo n.º 1
0
        public static bool Append(string poolName, string key, string value, int liveSecs = UnExpired, bool compress = false)
        {
            try
            {
                if (liveSecs < 0)
                {
                    return(false);
                }

                if (liveSecs == 0)
                {
                    liveSecs = UnExpired;
                }

                DateTime        expired = DateTime.Now.AddSeconds(liveSecs);
                MemcachedClient mc      = MemcacheItem.GetInstance(poolName);
                mc.PoolName          = poolName;
                mc.EnableCompression = compress;

                return(mc.Append(key, value, expired));
            }
            catch (Exception ex)
            {
                LogEngine.Write(LOGTYPE.ERROR, "MemcacheItem Append ex:", ex.ToString());
                return(false);
            }
        }
Exemplo n.º 2
0
        //2.Append test
        public void AppendTest()
        {
            MemcachedClient cache = MemcachedClient.GetInstance("BeITMemcached");

            cache.Append("BeIt", " baz");
            HandleLogs("[Cmd=Append]BeIt:" + cache.Get("BeIt").ToString());
        }
Exemplo n.º 3
0
    protected void btnMemPend(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 pkey=pendkey.Text.Trim();
        string select = Sele.Value;
        //string pdata=penddata.Text.Trim();
        byte[] b={49,50,51};
        ArraySegment<byte> pend=new ArraySegment<byte>(b);

        if (select.Equals("Prepend"))
        {
            if (client.Prepend(pkey, pend))
                Response.Write("<script>window.alert('向前追加数据成功!');window.location.href='../Mem_RedisTest.aspx'</script>");
            else
                Response.Write("<script>window.alert('向前追加数据失败!');window.location.href='../Mem_RedisTest.aspx'</script>");
        }
        else if(select.Equals("Append"))
        {
            if (client.Append(pkey, pend))
                Response.Write("<script>window.alert('追加数据成功!');window.location.href='../Mem_RedisTest.aspx'</script>");
            else
                Response.Write("<script>window.alert('追加数据失败!');window.location.href='../Mem_RedisTest.aspx'</script>");
        }

    }
Exemplo n.º 4
0
        //append test
        public void AppendTest()
        {
            MemcachedClient client = GetClient();
            var             r1     = client.Cas(StoreMode.Set, "CasAppend", "foo");
            var             r2     = client.Append("CasAppend", r1.Cas, new System.ArraySegment <byte>(new byte[] { (byte)'l' }));

            HandleLogs("[Cmd=Append]CasAppend:" + client.Get("CasAppend").ToString());
        }
        // 向后追加数据
        protected void Button9_Click(object sender, EventArgs e)
        {
            bool result = client.Append("b", "h");

            if (result)
            {
                Response.Write("<script>alert('向后追加数据成功!')</script>");
            }
            else
            {
                Response.Write("<script>alert('向后追加数据失败!')</script>");
            }
        }
Exemplo n.º 6
0
        public void AppendCASTest()
        {
            using (MemcachedClient client = GetClient())
            {
                // store the item
                var r1 = client.Cas(StoreMode.Set, "CasAppend", "foo");

                Assert.IsTrue(r1.Result, "Initial set failed.");
                Assert.AreNotEqual(r1.Cas, 0, "No cas value was returned.");

                var r2 = client.Append("CasAppend", r1.Cas, new System.ArraySegment <byte>(new byte[] { (byte)'l' }));

                Assert.IsTrue(r2.Result, "Append should have succeeded.");

                // get back the item and check the cas value (it should match the cas from the set)
                var r3 = client.GetWithCas <string>("CasAppend");

                Assert.AreEqual(r3.Result, "fool", "Invalid data returned; expected 'fool'.");
                Assert.AreEqual(r2.Cas, r3.Cas, "Cas values r2:r3 do not match.");

                var r4 = client.Append("CasAppend", r1.Cas, new System.ArraySegment <byte>(new byte[] { (byte)'l' }));
                Assert.IsFalse(r4.Result, "Append with invalid CAS should have failed.");
            }
        }
        public void AppendCASTest()
        {
            using (MemcachedClient client = GetClient())
            {
                // store the item
                var r1 = client.Cas(StoreMode.Set, "CasAppend", "foo");

                Assert.True(r1.Result, "Initial set failed.");
                Assert.NotEqual(r1.Cas, (ulong)0);

                var r2 = client.Append("CasAppend", r1.Cas, new System.ArraySegment <byte>(new byte[] { (byte)'l' }));

                Assert.True(r2.Result, "Append should have succeeded.");

                // get back the item and check the cas value (it should match the cas from the set)
                var r3 = client.GetWithCas <string>("CasAppend");

                Assert.Equal(r3.Result, "fool");
                Assert.Equal(r2.Cas, r3.Cas);

                var r4 = client.Append("CasAppend", r1.Cas, new System.ArraySegment <byte>(new byte[] { (byte)'l' }));
                Assert.False(r4.Result, "Append with invalid CAS should have failed.");
            }
        }
Exemplo n.º 8
0
 //后追加
 protected void Button8_Click(object sender, EventArgs e)
 {
     try
     {
         byte[] b = { 49 };
         ArraySegment <byte> pend = new ArraySegment <byte>(b);
         bool result = client.Append("y", pend);
         if (result)
         {
             Response.Write("<script>alert('向后追加数据成功!')</script>");
         }
         else
         {
             Response.Write("<script>alert('向后追加数据失败!')</script>");
         }
     }
     catch (Exception ex)
     {
         Response.Write("<script>alert('" + ex.Message + "')</script>");
     }
 }
Exemplo n.º 9
0
 public static bool Append(string strKey, byte[] data)
 {
     return(mc.Append(strKey, data));
 }
Exemplo n.º 10
0
 public bool Append(string key, ArraySegment <byte> data)
 {
     return(_client.Append(key, data));
 }
Exemplo n.º 11
0
 /// <summary>
 /// 在已有对象后追加内容
 /// </summary>
 /// <param name="strKey">缓存键</param>
 /// <param name="objValue">缓存内容</param>
 /// <returns></returns>
 public static bool Append(string strKey, object objValue)
 {
     return(cache.Append(strKey, objValue));
 }