Skip to content

Add STRLEN, GETRANGE and SETRANGE string commands#22

Merged
Rohit-Dnath merged 15 commits into
Rohit-Dnath:mainfrom
tchalikanti1705:add-string-commands
Jul 5, 2026
Merged

Add STRLEN, GETRANGE and SETRANGE string commands#22
Rohit-Dnath merged 15 commits into
Rohit-Dnath:mainfrom
tchalikanti1705:add-string-commands

Conversation

@tchalikanti1705

Copy link
Copy Markdown
Contributor

Summary

Adds the STRLEN, GETRANGE, and SETRANGE string 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, 0 if the key is missing
  • GETRANGE <key> <start> <end> — substring with Redis-style negative indexes and out-of-range clamping
  • SETRANGE <key> <offset> <value> — overwrites from offset, zero-padding with null bytes when it is past the end (creates the key if missing)
  • Added GetRange and SetRange methods in internal/store/string.go
  • Added tests in internal/server/server_test.go and documented the commands in docs/commands.md

Checklist

  • [ x] I've read CONTRIBUTING.md
  • [ x] Tests pass (go test ./...)
  • [ x] Code is formatted (go fmt ./...)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and SETRANGE server commands.
  • Added Store.GetRange / Store.SetRange string 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.

Comment thread internal/store/string.go
Comment on lines +185 to +192
if val == "" {
return len(cur), nil
}
size := offset + len(val)
if len(cur) > size {
size = len(cur)
}
buf := make([]byte, size)

@Rohit-Dnath Rohit-Dnath left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Rohit-Dnath Rohit-Dnath merged commit ddcd88c into Rohit-Dnath:main Jul 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add STRLEN / GETRANGE / SETRANGE string commands

3 participants