garnet
garnet copied to clipboard
API Coverage - Implement HSTRLEN
Here's your opportunity to implement a RESP command in Garnet!
Syntax:
HSTRLEN key field
Command description:
Returns the string length of the value associated with field in the hash stored at key. If the key or the field do not exist, 0 is returned.
Response:
Integer Reply: the string length of the value associated with the field, or zero when the field isn't present in the hash or the key doesn't exist at all.
How to approach this task:
- Add the new command info to the hashCommandsInfoMap 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/HashOps.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/HashCommands.cs)
- Add a new method to HashObjImpl which will perform the required operation on the hash object (Garnet.server/Objects/Hash/HashObjectImpl.cs)
- Add a new enum value to HashOperation and add the appropriate case to the switch in HashObject.Operate, in which you will call the method defined in step #8 (Garnet.server/Objects/Hash/HashObject.cs)
- Add an appropriate case to the switch in TransactionManager.HashObjectKeys (Garnet.server/Transaction/TxnKeyManager.cs)
- Add tests for the new command in the RespHashTests class (Garnet.test/RespHashTests.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!
I can help, can you assign this issue to me please? Thanks😊
I can help, can you assign this issue to me please? Thanks😊
Done! Thanks for your help! Let me know if you have any questions :)