Skip to content

Add MSETEX command #14434

Merged
StavRLevi merged 18 commits intoredis:unstablefrom
StavRLevi:RED-170542
Oct 23, 2025
Merged

Add MSETEX command #14434
StavRLevi merged 18 commits intoredis:unstablefrom
StavRLevi:RED-170542

Conversation

@StavRLevi
Copy link
Collaborator

@StavRLevi StavRLevi commented Oct 16, 2025

Introduce a new command MSETEX to set multiple string keys with a shared expiration in a single atomic operation. Also with flexible argument parsing.

Syntax:
MSETEX numkeys key value [key value …] [XX | NX] [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL]

Sets the given keys to their respective values.
This command is an extension of the MSETNX that adds expiration and XX options.

Options:
EX seconds - Set the specified expiration time, in seconds
PX milliseconds - Set the specified expiration time, in milliseconds
EXAT timestamp-seconds - Set the specified Unix time at which the keys will expire, in seconds
PXAT timestamp-milliseconds - Set the specified Unix time at which the keys will expire, in milliseconds
KEEPTTL - Retain the time to live associated with the keys
XX - Only set the keys and their expiration if all already exist
NX - Only set the keys and their expiration if none exist

Flexible Argument Parsing examples:

  • MSETEX 2 k1 v1 k2 v2 EX 10
  • MSETEX 2 k1 v1 k2 v2 NX PX 5000
  • MSETEX 2 k1 v1 k2 v2 NX EX 10

Return Values:
Integer reply: 1 - All keys were set successfully
Integer reply: 0 - No keys were set (due to NX/XX conditions)
Error reply - Syntax error or invalid arguments

@StavRLevi StavRLevi requested review from minchopaskal and sundb and removed request for sundb October 16, 2025 11:24
@StavRLevi StavRLevi added the release-notes indication that this issue needs to be mentioned in the release notes label Oct 19, 2025
@sundb sundb requested a review from minchopaskal October 22, 2025 09:42
@sundb
Copy link
Collaborator

sundb commented Oct 22, 2025

fully CI only with runtest: https://github.com/redis/redis/actions/runs/18716621124

@sundb sundb added the state:needs-doc-pr requires a PR to redis-doc repository label Oct 22, 2025
src/t_string.c Outdated
args->kv_count = (int)kv_count_long;
args->kv_start = j + 2;

j = j + 1 + ((long long)kv_count_long * 2); /* Skip "KEYS", numkeys, and all key-value pairs */
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's unnecessary, now we know that kv_count_long is legal.
On the other hand, j is int, and this code will cause confusion.
and maybe we can add a test for this.

Suggested change
j = j + 1 + ((long long)kv_count_long * 2); /* Skip "KEYS", numkeys, and all key-value pairs */
j = j + 1 + (kv_count_long * 2); /* Skip "KEYS", numkeys, and all key-value pairs */

@sundb
Copy link
Collaborator

sundb commented Oct 23, 2025

@StavRLevi Please confirm that all the top comments have been updated.

@StavRLevi StavRLevi merged commit 52ea47b into redis:unstable Oct 23, 2025
23 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Redis 8.4 Oct 23, 2025
Comment on lines +731 to +734
if ((args.flags & OBJ_SET_NX) && (args.flags & OBJ_SET_XX)) {
addReplyErrorObject(c, shared.syntaxerr);
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This check is not needed anymore because of parseExtendedStringArgumentsOrReply

sundb added a commit that referenced this pull request Oct 27, 2025
In PR #14434, we made the keys
parameter flexible, meaning it could appear anywhere among the command
arguments. However, this also made key parsing more complex, since we
could no longer determine the fixed position of key arguments.
Therefore, in this PR, we reverted it back to using fixed positions for
the keys.

And also fix this
[comment](#14434 (comment)).

---------

Co-authored-by: Yuan Wang <yuan.wang@redis.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes state:needs-doc-pr requires a PR to redis-doc repository

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants