Add STRLEN, GETRANGE and SETRANGE string commands#22
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Redis-compatible string commands (STRLEN, GETRANGE, SETRANGE) to RAMen, extending the existing string-command surface area with common client-needed operations and associated tests/docs.
Changes:
- Registered and implemented
STRLEN,GETRANGE, andSETRANGEserver commands. - Added
Store.GetRange/Store.SetRangestring operations to back the new commands. - Added integration tests and updated command documentation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/store/string.go | Adds GetRange/SetRange store methods implementing Redis-style substring and ranged overwrite semantics. |
| internal/server/cmd_string.go | Implements RESP handlers for STRLEN, GETRANGE, SETRANGE, including offset/size validation for SETRANGE. |
| internal/server/commands.go | Registers the new string commands in the server command map. |
| internal/server/server_test.go | Adds end-to-end tests for STRLEN, GETRANGE, and SETRANGE behavior and error handling. |
| docs/commands.md | Documents the new commands in the command reference table. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if val == "" { | ||
| return len(cur), nil | ||
| } | ||
| size := offset + len(val) | ||
| if len(cur) > size { | ||
| size = len(cur) | ||
| } | ||
| buf := make([]byte, size) |
Rohit-Dnath
left a comment
There was a problem hiding this comment.
Really nice work on this one, thanks @tchalikanti1705. I pulled it down locally and everything checks out clean: build, go vet, the full test suite, and gofmt all pass. The store methods follow the existing Append/IncrBy patterns closely, and the Redis semantics for negative indexes and zero-padding are spot on.
What stood out to me was the overflow-safe size guard on SETRANGE and the test that fires a huge offset then pings to confirm the server didn't crash. That's exactly the kind of edge-case thinking I like to see, and it went beyond what the issue asked for.
One small non-blocking follow-up if you feel like it later: STRLEN has a WRONGTYPE test but GETRANGE and SETRANGE don't. The code handles it correctly, it's just untested. Not required for this merge though.
Merging now. Appreciate the contribution.
Summary
Adds the
STRLEN,GETRANGE, andSETRANGEstring commands so RAMen matches Redis for these common string operations.Related Issue
Closes #3
Changes
STRLEN <key>— returns the byte length of the string value,0if the key is missingGETRANGE <key> <start> <end>— substring with Redis-style negative indexes and out-of-range clampingSETRANGE <key> <offset> <value>— overwrites fromoffset, zero-padding with null bytes when it is past the end (creates the key if missing)GetRangeandSetRangemethods ininternal/store/string.gointernal/server/server_test.goand documented the commands indocs/commands.mdChecklist
go test ./...)go fmt ./...)