Skip to content

feat(string): add MGET and MSET batch string operations - #145

Open
darion-yaphet wants to merge 2 commits into
redis:mainfrom
darion-yaphet:feat/mget-mset-batch-string
Open

feat(string): add MGET and MSET batch string operations#145
darion-yaphet wants to merge 2 commits into
redis:mainfrom
darion-yaphet:feat/mget-mset-batch-string

Conversation

@darion-yaphet

@darion-yaphet darion-yaphet commented May 26, 2026

Copy link
Copy Markdown
  • Add mset() tool to set multiple keys atomically in a single call
  • Add mget() tool to retrieve multiple keys and return a key-value dict
  • Support str/int/float/dict/bytes value encoding in mset
  • Return None for missing keys in mget result

Note

Low Risk
New optional MCP tools alongside existing set/get; no changes to auth, existing set/get behavior, or expiration semantics.

Overview
Adds two new MCP Redis string tools in string.py: mset for atomic multi-key writes and mget for bulk reads.

mset accepts a mappings dict, rejects empty input, normalizes values (JSON for dicts, UTF-8 decode for bytes with a hard error on invalid UTF-8, str() otherwise), then calls Redis MSET and returns a success string listing keys.

mget accepts a key list, rejects empty input, calls Redis MGET, and returns a key→value dict with None for missing keys. Byte values are UTF-8 decoded when possible, otherwise returned as repr(bytes).

Reviewed by Cursor Bugbot for commit 8eb2978. Bugbot is set up for automated code reviews on this repo. Configure here.

- Add mset() tool to set multiple keys atomically in a single call
- Add mget() tool to retrieve multiple keys and return a key-value dict
- Support str/int/float/dict/bytes value encoding in mset
- Return None for missing keys in mget result
Comment thread src/tools/string.py

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 54d1cc5. Configure here.

Comment thread src/tools/string.py Outdated
- mget: add isinstance(value, bytes) guard before calling .decode()
  to avoid AttributeError when connection uses decode_responses=True
- mset: normalize values to str instead of bytes, consistent with
  the decode_responses=True connection default
@darion-yaphet
darion-yaphet force-pushed the feat/mget-mset-batch-string branch from 54d1cc5 to 8eb2978 Compare May 26, 2026 15:18
@dantovska

Copy link
Copy Markdown
Contributor

Hi @darion-yaphet!

Thank you for the contribution!

Adding these tools make sense and will improve token efficiency.

However, we are already at 53 tools and adding more makes LLM's selection job harder. We already expose the needed tools to add a single key which is also used for adding multiple keys. It also may be confusing which one to decide to use, depending on the LLM.

Speed wise, MCP also executes them in parallel so it is no difference there.

So I propose for now to hold on with these tools, until we optimize the number of the total tools and then revisit this case again.

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.

2 participants