garnet
garnet copied to clipboard
API Coverage - Implement SMOVE
Here's your opportunity to implement a couple of RESP commands in Garnet!
SMOVE
Syntax:
SMOVE source destination member
Command description:
Move member from the set at source to the set at destination.
If the source set does not exist or does not contain the specified element, no operation is performed and 0 is returned. Otherwise, the element is removed from the source set and added to the destination set. When the specified element already exists in the destination set, it is only removed from the source set.
An error is returned if source or destination does not hold a set value.
Response:
One of the following:
Integer reply: 1 if the element is moved.
Integer reply: 0 if the element is not a member of source and no operation was performed.
How to approach this task:
- Add the new command info to the setCommandsInfoMap in the RespCommandsInfo class (Garnet.server/Resp/RespCommandsInfo.cs)
- Add the new command string to the returned HashSet in the RespInfo.GetCommands method (Garnet.server/Resp/RespInfo.cs)
- 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)
- Implement the wrapper method to the storage layer in StorageSession (Garnet.server/Storage/Session/ObjectStore/SetOps.cs)
- 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)
- 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)
- Add a new method to SetObjImpl which will perform the required operation on the hash object (Garnet.server/Objects/Set/SetObjectImpl.cs)
- 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)
- Add an appropriate case to the switch in TransactionManager.SetObjectKeys (Garnet.server/Transaction/TxnKeyManager.cs)
- 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!
Hello, I would like to give this a go. This is my first time contributing so I will probably have questions.
Hello, I would like to give this a go. This is my first time contributing so I will probably have questions.
Go ahead! Please LMK if you have any questions...
@TalZaccai I just had a question about one thing, then I will be ready to make a pull request. For the method in SetObjectImpl.cs, how should I access the other set to add the item to it? Is there a method I can use for this?
@TalZaccai I just had a question about one thing, then I will be ready to make a pull request. For the method in SetObjectImpl.cs, how should I access the other set to add the item to it? Is there a method I can use for this?
Good question! You don't :) SetObjectImpl strictly interacts with the current object, you'll need to call the storage layer multiple times to interact with different object. You can refer to other commands that interact with more than one object - take a look at LMOVE for example, it should be pretty similar!
OK thank you. I created a pull request, what would the next steps be?
OK thank you. I created a pull request, what would the next steps be?
If it's ready for review I'll go over it in the next few days and post comments if I have any :)