Skip to content

Commit

Permalink
more bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TalZaccai committed May 23, 2024
1 parent 5caeb13 commit cd32c88
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions libs/server/Objects/SortedSetGeo/SortedSetGeoObjectImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private void GeoAdd(byte* input, int length, byte* output)
_output->opsDone++;

this.UpdateSize(member);
elementsChanged++;
}
}
else if (!nx && scoreStored != score)
Expand Down
2 changes: 1 addition & 1 deletion libs/server/Resp/BasicCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private bool NetworkGetRange<TGarnetApi>(byte* ptr, ref TGarnetApi storageApi)
{
sessionMetrics?.incr_total_notfound();
Debug.Assert(o.IsSpanByte);
while (!RespWriteUtils.WriteDirect(CmdStrings.RESP_ERRNOTFOUND, ref dcurr, dend))
while (!RespWriteUtils.WriteDirect(CmdStrings.RESP_EMPTY, ref dcurr, dend))
SendAndReset();
}

Expand Down
25 changes: 21 additions & 4 deletions libs/server/Resp/Objects/SortedSetGeoCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,11 @@ private unsafe bool GeoCommands<TGarnetApi>(int count, byte* ptr, SortedSetOpera
{
int paramsRequiredInCommand = 0;
string cmd = string.Empty;
var responseWhenNotFound = CmdStrings.RESP_EMPTYLIST;
switch (op)
{
case SortedSetOperation.GEODIST:
paramsRequiredInCommand = 3;
cmd = "GEODIST";
responseWhenNotFound = CmdStrings.RESP_ERRNOTFOUND;
break;
case SortedSetOperation.GEOHASH:
paramsRequiredInCommand = 1;
Expand Down Expand Up @@ -181,8 +179,27 @@ private unsafe bool GeoCommands<TGarnetApi>(int count, byte* ptr, SortedSetOpera
ptr += objOutputHeader.bytesDone;
break;
case GarnetStatus.NOTFOUND:
while (!RespWriteUtils.WriteDirect(responseWhenNotFound, ref dcurr, dend))
SendAndReset();
var tokens = ReadLeftToken(inputCount, ref ptr);
if (tokens < inputCount)
return false;

switch (op)
{
case SortedSetOperation.GEODIST:
while (!RespWriteUtils.WriteDirect(CmdStrings.RESP_ERRNOTFOUND, ref dcurr, dend))
SendAndReset();
break;
default:
while (!RespWriteUtils.WriteArrayLength(inputCount, ref dcurr, dend))
SendAndReset();
for (var i = 0; i < inputCount; i++)
{
while (!RespWriteUtils.WriteNullArray(ref dcurr, dend))
SendAndReset();
}
break;
}

break;
}
}
Expand Down
11 changes: 5 additions & 6 deletions test/Garnet.test/RespSortedSetGeoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,6 @@ public void CanDoGeoAddWhenInvalidPairLC(int bytesSent)
var actualValue = Encoding.ASCII.GetString(response).Substring(0, expectedResponse.Length);
Assert.AreEqual(expectedResponse, actualValue);

// Check GEOADD with insufficient parameters
//response = lightClientRequest.SendCommandChunks("GEOADD Sicily NX CH 13.361389 38.115556", bytesSent);
//expectedResponse = $"-{Encoding.ASCII.GetString(CmdStrings.RESP_ERR_GENERIC_SYNTAX_ERROR)}\r\n";
//actualValue = Encoding.ASCII.GetString(response).Substring(0, expectedResponse.Length);
//Assert.AreEqual(expectedResponse, actualValue);

response = lightClientRequest.SendCommandChunks("GEOADD Sicily NX 13.361389 38.115556 Palermo 15.087269 37.502669 Catania", bytesSent);
expectedResponse = ":2\r\n";
actualValue = Encoding.ASCII.GetString(response).Substring(0, expectedResponse.Length);
Expand Down Expand Up @@ -433,6 +427,11 @@ public void CanUseGeoPosLC(int bytesSent)
var response = lightClientRequest.Execute("GEOADD Sicily 13.361389 38.115556 Palermo 15.087269 37.502669 Catania", "PING", expectedResponse.Length, bytesSent);
Assert.AreEqual(expectedResponse, response);

// GEOPOS with unknown key
response = lightClientRequest.Execute("GEOPOS Unknown Palermo Catania", expectedResponse.Length, bytesSent);
expectedResponse = "*2\r\n*-1\r\n*-1\r\n";
Assert.AreEqual(expectedResponse, response);

expectedResponse = "*3\r\n*2\r\n$18\r\n13.361389338970184\r\n$17\r\n38.11555668711662\r\n*2\r\n$18\r\n15.087267458438873\r\n$18\r\n37.502669245004654\r\n*-1\r\n+PONG\r\n";
response = lightClientRequest.Execute("GEOPOS Sicily Palermo Catania Unknown", "PING", expectedResponse.Length, bytesSent);
Assert.AreEqual(expectedResponse, response);
Expand Down
2 changes: 1 addition & 1 deletion test/Garnet.test/RespTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ public void GetSliceTest()
string value = "0123456789";

var resp = (string)db.StringGetRange(key, 2, 10);
Assert.AreEqual(null, resp);
Assert.AreEqual(string.Empty, resp);
Assert.AreEqual(true, db.StringSet(key, value));

//0,0
Expand Down

0 comments on commit cd32c88

Please sign in to comment.