Skip to content

Implement MSETEX command #6329

@romange

Description

@romange

Goal

Implement the MSETEX command as described in Redis documentation.

Command Syntax

MSETEX numkeys key value [key value ...] [NX|XX] [EX seconds|PX milliseconds|EXAT timestamp|PXAT timestamp|KEEPTTL]

Implementation Details

  1. Command Registration:

    • Register MSETEX in src/server/command_registry.cc (or string_family.cc registration block).
    • It should be a write command.
  2. Implementation in src/server/string_family.cc:

    • Implement a new function MSetEx (or similar) to handle the command.
    • Argument Parsing:
      • Parse numkeys to determine how many key-value pairs to expect.
      • Parse the key-value pairs.
      • Parse the optional arguments (expiration, NX/XX, KEEPTTL) into SetCmd::SetParams.
    • Logic:
      • The existing OpMSet function currently iterates over keys and calls SetCmd::Set with default parameters.
      • Refactor OpMSet to accept SetCmd::SetParams as an argument, or create a new OpMSetEx function that does so.
      • Ensure the operation is atomic (runs in a single hop/transaction), similar to MSET.
      • Use SetCmd class which already handles the logic for setting values with options.
  3. Tests:

    • Add unit tests in src/server/string_family_test.cc covering:
      • Basic usage with expiration.
      • NX and XX options.
      • KEEPTTL option.
      • Invalid arguments (wrong numkeys, invalid options).
      • Atomicity (all or nothing, though hard to test directly in unit tests, verify behavior).

References

  • src/server/string_family.cc: OpMSet, SetCmd
  • https://redis.io/docs/latest/commands/msetex/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions