public static bool Prepend(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.Prepend(key, value, expired)); } catch (Exception ex) { LogEngine.Write(LOGTYPE.ERROR, "MemcacheItem Prepend ex:", ex.ToString()); return(false); } }
//12.Prepend test public void PrependTest() { MemcachedClient cache = MemcachedClient.GetInstance("BeITMemcached"); cache.Prepend("BeIt", "foo prepend"); HandleLogs("[Cmd=Prepend]BeIt:" + cache.Get("BeIt").ToString()); }
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>"); } }
//test Prepend public void PrependTest() { MemcachedClient client = GetClient(); var r1 = client.Cas(StoreMode.Set, "CasPrepend", "ool"); var r2 = client.Prepend("CasPrepend", r1.Cas, new System.ArraySegment <byte>(new byte[] { (byte)'f' })); HandleLogs("[Cmd=Prepend]CasPrepend:" + client.Get("CasPrepend").ToString()); }
//向前追加 protected void Button8_Click(object sender, EventArgs e) { bool result = client.Prepend("b", "q"); if (result) { Response.Write("<script>alert('向前追加数据成功!')</script>"); } else { Response.Write("<script>alert('向前追加数据失败!')</script>"); } }
public void PrependCASTest() { using (MemcachedClient client = GetClient()) { // store the item var r1 = client.Cas(StoreMode.Set, "CasPrepend", "ool"); Assert.IsTrue(r1.Result, "Initial set failed."); Assert.AreNotEqual(r1.Cas, 0, "No cas value was returned."); var r2 = client.Prepend("CasPrepend", r1.Cas, new System.ArraySegment <byte>(new byte[] { (byte)'f' })); Assert.IsTrue(r2.Result, "Prepend 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>("CasPrepend"); 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.Prepend("CasPrepend", r1.Cas, new System.ArraySegment <byte>(new byte[] { (byte)'l' })); Assert.IsFalse(r4.Result, "Prepend with invalid CAS should have failed."); } }
public void PrependCASTest() { using (MemcachedClient client = GetClient()) { // store the item var r1 = client.Cas(StoreMode.Set, "CasPrepend", "ool"); Assert.True(r1.Result, "Initial set failed."); Assert.NotEqual(r1.Cas, (ulong)0); var r2 = client.Prepend("CasPrepend", r1.Cas, new System.ArraySegment <byte>(new byte[] { (byte)'f' })); Assert.True(r2.Result, "Prepend 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>("CasPrepend"); Assert.Equal(r3.Result, "fool"); Assert.Equal(r2.Cas, r3.Cas); var r4 = client.Prepend("CasPrepend", r1.Cas, new System.ArraySegment <byte>(new byte[] { (byte)'l' })); Assert.False(r4.Result, "Prepend with invalid CAS should have failed."); } }
//前追加 protected void Button7_Click(object sender, EventArgs e) { try { byte[] b = { 50 }; ArraySegment <byte> pend = new ArraySegment <byte>(b); bool result = client.Prepend("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>"); } }
public static bool Prepend(string key, byte[] data) { return(mc.Prepend(key, data)); }
public bool Prepend(string key, ArraySegment <byte> data) { return(_client.Prepend(key, data)); }
/// <summary> /// 在已有对象前插入内容 /// </summary> /// <param name="strKey">缓存键</param> /// <param name="objValue">缓存内容</param> /// <returns></returns> public static bool Prepend(string strKey, object objValue) { return(cache.Prepend(strKey, objValue)); }