garnet icon indicating copy to clipboard operation
garnet copied to clipboard

API Coverage - Implement SUNION

Open TalZaccai opened this issue 1 year ago • 3 comments

Here's your opportunity to implement a couple of RESP commands in Garnet!

SUNION

Syntax: SUNION key [key ...]

Command description: Returns the members of the set resulting from the union of all the given sets.

For example:

key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SUNION key1 key2 key3 = {a,b,c,d,e}

Keys that do not exist are considered to be empty sets.

Response:

Array reply: a list with members of the resulting set.


How to approach this task:

  1. Add the new command info to the setCommandsInfoMap in the RespCommandsInfo class (Garnet.server/Resp/RespCommandsInfo.cs)
  2. Add the new command string to the returned HashSet in the RespInfo.GetCommands method (Garnet.server/Resp/RespInfo.cs)
  3. Add the appropriate fast parsing logic for the new command in the RespCommand.FastParseArrayCommand method (use other commands as reference) (Garnet.server/Resp/RespCommand.cs)
  4. Implement the wrapper method to the storage layer in StorageSession (Garnet.server/Storage/Session/ObjectStore/SetOps.cs)
  5. Define a new method in IGarnetAPI and implement it in GarnetApiObjectCommands, calling the method you have implemented in step #4 (Garnet.server/API/IGarnetAPI.cs, Garnet.server/API/GarnetApiObjectCommands.cs)
  6. Add a new method to the RespServerSession class which will call the storage API and return the appropriate response (Garnet.server/Resp/Objects/SetCommands.cs)
  7. Add a new method to SetObjImpl which will perform the required operation on the hash object (Garnet.server/Objects/Set/SetObjectImpl.cs)
  8. Add a new enum value to SetOperation and add the appropriate case to the switch in SetObject.Operate, in which you will call the method defined in step #8 (Garnet.server/Objects/Set/SetObject.cs)
  9. Add an appropriate case to the switch in TransactionManager.SetObjectKeys (Garnet.server/Transaction/TxnKeyManager.cs)
  10. Add tests for the new command in the RespSetTests class (Garnet.test/RespSetTests.cs)

Tip: First add a simple test that calls the new command and use it to debug as you develop, it will make your life much easier!

If you have any questions, the Garnet team is here to help!

TalZaccai avatar Mar 28 '24 20:03 TalZaccai

I want to give it a try

argsno avatar Mar 28 '24 23:03 argsno

I want to give it a try

Go for it! LMK if you have any questions :)

TalZaccai avatar Mar 29 '24 04:03 TalZaccai

@TalZaccai I need help with how to delete an existing key (especially if it is in the main store) when storing the value.

argsno avatar Mar 30 '24 07:03 argsno

@TalZaccai Is there going to be a separate issue for SUNIONSTORE?

roncrush avatar Apr 18 '24 12:04 roncrush

@TalZaccai Is there going to be a separate issue for SUNIONSTORE?

Yes, I was waiting for SUNION to be merged before posting :)

TalZaccai avatar Apr 18 '24 17:04 TalZaccai