From 4d38f772323ac23c3691c0df7e19033de2337eb2 Mon Sep 17 00:00:00 2001 From: Hamdaan Khalid Date: Fri, 20 Dec 2024 01:31:32 -0800 Subject: [PATCH] reuse code smartly --- .../Storage/Functions/MainStore/RMWMethods.cs | 14 ++------------ test/Garnet.test/RespEtagTests.cs | 4 ++-- website/docs/commands/garnet-specific.md | 5 ++--- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/libs/server/Storage/Functions/MainStore/RMWMethods.cs b/libs/server/Storage/Functions/MainStore/RMWMethods.cs index 0b08be5f45..97a95edb05 100644 --- a/libs/server/Storage/Functions/MainStore/RMWMethods.cs +++ b/libs/server/Storage/Functions/MainStore/RMWMethods.cs @@ -324,12 +324,7 @@ private bool InPlaceUpdaterWorker(ref SpanByte key, ref RawStringInput input, re if (oldEtag != etagFromClient) { - // write back array of the format [etag, value] - var valueToWrite = value.AsReadOnlySpan(etagIgnoredOffset); - var digitsInLenOfValue = NumUtils.NumDigitsInLong(valueToWrite.Length); - // *2\r\n: + + \r\n + $ + + \r\n + + \r\n - var numDigitsInEtag = NumUtils.NumDigitsInLong(oldEtag); - WriteValAndEtagToDst(4 + 1 + numDigitsInEtag + 2 + 1 + digitsInLenOfValue + 2 + valueToWrite.Length + 2, ref valueToWrite, oldEtag, ref output, writeDirect: false); + CopyRespToWithInput(ref input, ref value, ref output, isFromPending: false, etagIgnoredOffset, etagIgnoredEnd, hasEtagInVal: recordInfo.ETag); return true; } @@ -786,12 +781,7 @@ public bool NeedCopyUpdate(ref SpanByte key, ref RawStringInput input, ref SpanB if (existingEtag != etagToCheckWith) { - // write back array of the format [etag, value] - var valueToWrite = oldValue.AsReadOnlySpan(etagIgnoredOffset); - var digitsInLenOfValue = NumUtils.NumDigitsInLong(valueToWrite.Length); - // *2\r\n: + + \r\n + $ + + \r\n + \r\n - var numDigitsInEtag = NumUtils.NumDigitsInLong(existingEtag); - WriteValAndEtagToDst(4 + 1 + numDigitsInEtag + 2 + 1 + digitsInLenOfValue + 2 + valueToWrite.Length + 2, ref valueToWrite, existingEtag, ref output, writeDirect: false); + CopyRespToWithInput(ref input, ref oldValue, ref output, isFromPending: false, etagIgnoredOffset, etagIgnoredEnd, hasEtagInVal: rmwInfo.RecordInfo.ETag); return false; } diff --git a/test/Garnet.test/RespEtagTests.cs b/test/Garnet.test/RespEtagTests.cs index 32b5138e97..75f0e27b4c 100644 --- a/test/Garnet.test/RespEtagTests.cs +++ b/test/Garnet.test/RespEtagTests.cs @@ -127,7 +127,7 @@ public void SetIfMatchWorksWithExpiration() // TTL should be retained ttl = db.KeyTimeToLive(key); ClassicAssert.IsTrue(ttl.HasValue); - + db.KeyDelete(key); // cleanup // Scenario: Key existed before and had expiration @@ -207,7 +207,7 @@ public void SetIfMatchWorksWithExpiration() // confirm expiration retained -> TTL should exist ttl = db.KeyTimeToLive(key); - ClassicAssert.IsTrue(ttl.HasValue); + ClassicAssert.IsTrue(ttl.HasValue); } #endregion diff --git a/website/docs/commands/garnet-specific.md b/website/docs/commands/garnet-specific.md index 07610d8b44..605792a314 100644 --- a/website/docs/commands/garnet-specific.md +++ b/website/docs/commands/garnet-specific.md @@ -155,7 +155,7 @@ One of the following: #### **Syntax** ```bash -SETIFMATCH key value etag +SETIFMATCH key value etag [EX || PX expiration] ``` Updates the value of a key if the provided ETag matches the current ETag of the key. @@ -164,9 +164,8 @@ Updates the value of a key if the provided ETag matches the current ETag of the One of the following: -- **Integer reply**: The updated ETag if the value was successfully updated. +- **Array reply**: The updated ETag if the value was successfully updated, and no a - **Nil reply**: If the key does not exist. -- **Simple string reply**: If the provided ETag does not match the current ETag returns VAL_NOT_FOUND ---