Skip to content

Commit

Permalink
Cluster Mode SELECT Command (#362)
Browse files Browse the repository at this point in the history
* return error select not supported with cluster mode

* remove second check for enable cluster
  • Loading branch information
vazois committed May 6, 2024
1 parent 42ccdf3 commit b8a2674
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
19 changes: 14 additions & 5 deletions libs/server/Resp/ArrayCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -668,15 +668,25 @@ private bool NetworkSELECT(byte* ptr)

readHead = (int)(ptr - recvBufferPtr);

if (string.Equals(result, "0"))
if (storeWrapper.serverOptions.EnableCluster)
{
while (!RespWriteUtils.WriteDirect(CmdStrings.RESP_OK, ref dcurr, dend))
// Cluster mode does not allow DBID
while (!RespWriteUtils.WriteError(CmdStrings.RESP_ERR_GENERIC_SELECT_CLUSTER_MODE, ref dcurr, dend))
SendAndReset();
}
else
{
while (!RespWriteUtils.WriteError("ERR invalid database index."u8, ref dcurr, dend))
SendAndReset();

if (string.Equals(result, "0"))
{
while (!RespWriteUtils.WriteDirect(CmdStrings.RESP_OK, ref dcurr, dend))
SendAndReset();
}
else
{
while (!RespWriteUtils.WriteError(CmdStrings.RESP_ERR_GENERIC_SELECT_INVALID_INDEX, ref dcurr, dend))
SendAndReset();
}
}
return true;
}
Expand Down Expand Up @@ -728,7 +738,6 @@ private bool NetworkKEYS<TGarnetApi>(int count, byte* ptr, ref TGarnetApi storag
return true;
}


private bool NetworkSCAN<TGarnetApi>(int count, byte* ptr, ref TGarnetApi storageApi)
where TGarnetApi : IGarnetApi
{
Expand Down
3 changes: 3 additions & 0 deletions libs/server/Resp/CmdStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public static ReadOnlySpan<byte> GetConfig(ReadOnlySpan<byte> key)
public static ReadOnlySpan<byte> RESP_ERR_GENERIC_VALUE_IS_NOT_INTEGER => "ERR value is not an integer or out of range."u8;
public static ReadOnlySpan<byte> RESP_ERR_GENERIC_UKNOWN_SUBCOMMAND => "ERR Unknown subcommand. Try LATENCY HELP."u8;
public static ReadOnlySpan<byte> RESP_ERR_GENERIC_INDEX_OUT_RANGE => "ERR index out of range"u8;
public static ReadOnlySpan<byte> RESP_ERR_GENERIC_SELECT_INVALID_INDEX => "ERR invalid database index."u8;
public static ReadOnlySpan<byte> RESP_ERR_GENERIC_SELECT_CLUSTER_MODE => "ERR SELECT is not allowed in cluster mode"u8;

/// <summary>
/// Response string templates
/// </summary>
Expand Down

0 comments on commit b8a2674

Please sign in to comment.