diff --git a/Enyim.Caching/MemcachedClient.cs b/Enyim.Caching/MemcachedClient.cs index 31d2c3f0..a9bf0f4e 100755 --- a/Enyim.Caching/MemcachedClient.cs +++ b/Enyim.Caching/MemcachedClient.cs @@ -619,7 +619,7 @@ protected virtual bool PerformConcatenate(ConcatenationMode mode, string key, re if (node != null) { - var command = this.pool.OperationFactory.Concat(mode, hashedKey, 0, data); + var command = this.pool.OperationFactory.Concat(mode, hashedKey, cas, data); var retval = node.Execute(command); cas = command.CasValue; diff --git a/Membase/MembaseClient.cs b/Membase/MembaseClient.cs index 8031a423..687659d8 100644 --- a/Membase/MembaseClient.cs +++ b/Membase/MembaseClient.cs @@ -143,7 +143,7 @@ protected override bool PerformConcatenate(ConcatenationMode mode, string key, r if (node != null) { - var command = this.Pool.OperationFactory.Concat(mode, hashedKey, 0, data); + var command = this.Pool.OperationFactory.Concat(mode, hashedKey, cas, data); var retval = this.ExecuteWithRedirect(node, command); cas = command.CasValue; diff --git a/MemcachedTest/BinaryMemcachedClientTest.cs b/MemcachedTest/BinaryMemcachedClientTest.cs index 31fd88b3..552ff704 100644 --- a/MemcachedTest/BinaryMemcachedClientTest.cs +++ b/MemcachedTest/BinaryMemcachedClientTest.cs @@ -84,6 +84,58 @@ public virtual void CASTest() Assert.AreEqual(r5.Result, "baz", "Invalid data returned; excpected 'baz'."); } } + + [TestCase] + 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(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("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(new byte[] { (byte)'l' })); + Assert.IsFalse(r4.Result, "Append with invalid CAS should have failed."); + } + } + + [TestCase] + 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(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("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(new byte[] { (byte)'l' })); + Assert.IsFalse(r4.Result, "Prepend with invalid CAS should have failed."); + } + } } }