Skip to content

New MSETEX command allows to set an expiration time with MSET#3121

Merged
ranshid merged 11 commits into
valkey-io:unstablefrom
enjoy-binbin:msetex_command
Mar 10, 2026
Merged

New MSETEX command allows to set an expiration time with MSET#3121
ranshid merged 11 commits into
valkey-io:unstablefrom
enjoy-binbin:msetex_command

Conversation

@enjoy-binbin

@enjoy-binbin enjoy-binbin commented Jan 28, 2026

Copy link
Copy Markdown
Member

It's a combination of MSET and EXPIRE, which allows us to set an expiration
time simultaneously with the MSET operation.

Syntax for the new MSETEX command:

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

The MSETEX command supports a set of options (like SET command):

  • EX seconds -- Set the specified expire time, in seconds (a positive integer).
  • PX milliseconds -- Set the specified expire time, in milliseconds (a positive
    integer).
  • EXAT timestamp-seconds -- Set the specified Unix time at which the keys will
    expire, in seconds (a positive integer).
  • PXAT timestamp-milliseconds -- Set the specified Unix time at which the keys
    will expire, in milliseconds (a positive integer).
  • KEEPTTL -- Retain the time to live associated with the keys.
  • NX -- Only set the keys if all keys do not already exist.
  • XX -- Only set the keys if all keys already exists.

Return Value (like MSETNX command):

  • Integer reply: 0 if no key was set due to NX or XX options.
  • Integer reply: 1 if all the keys were set.

Closes #2592

It's a combination of MSET and EXPIRE, which allows us to set an expiration
time simultaneously with the MSET operation.

Syntax for the new MSETEX command:
```
/* MSETEX numkeys key value [key value ...] [NX | XX]
 *     [EX seconds | PX milliseconds |
 *      EXAT seconds-timestamp | PXAT milliseconds-timestamp | KEEPTTL] */
```

The MSETEX command supports a set of options (like SET command):
- EX seconds -- Set the specified expire time, in seconds (a positive integer).
- PX milliseconds -- Set the specified expire time, in milliseconds (a positive
  integer).
- EXAT timestamp-seconds -- Set the specified Unix time at which the keys will
  expire, in seconds (a positive integer).
- PXAT timestamp-milliseconds -- Set the specified Unix time at which the keys
  will expire, in milliseconds (a positive integer).
- KEEPTTL -- Retain the time to live associated with the keys.
- NX -- Only set the keys if all keys do not already exist.
- XX -- Only set the key if all keys already exists.

Return Value (like MSETNX command):
- Integer reply: 0 if no key was set due to NX or XX options.
- Integer reply: 1 if all the keys were set.

Signed-off-by: Binbin <binloveplay1314@qq.com>
@enjoy-binbin

Copy link
Copy Markdown
Member Author

Redis added this command in 8.4, and i've also received requests indicating that people want to use it in Valkey.
Considering that MSET is popular and + EXPIRE is also popular, added this command.
This command is compatible with the Redis API (options and return values).

@codecov

codecov Bot commented Jan 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.99%. Comparing base (5deebd0) to head (e0b429c).
⚠️ Report is 3 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3121      +/-   ##
============================================
- Coverage     75.02%   74.99%   -0.03%     
============================================
  Files           129      129              
  Lines         71632    71681      +49     
============================================
+ Hits          53739    53759      +20     
- Misses        17893    17922      +29     
Files with missing lines Coverage Δ
src/commands.def 100.00% <ø> (ø)
src/db.c 94.21% <ø> (-0.15%) ⬇️
src/server.c 89.49% <100.00%> (+0.07%) ⬆️
src/server.h 100.00% <ø> (ø)
src/t_hash.c 95.39% <100.00%> (ø)
src/t_string.c 97.98% <100.00%> (+0.18%) ⬆️

... and 19 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/commands/msetex.json
Comment thread src/t_string.c
@zuiderkwast zuiderkwast added the major-decision-pending Major decision pending by TSC team label Jan 31, 2026
@zuiderkwast

Copy link
Copy Markdown
Contributor

We have already discussed this in the core team meeting. I don't remember exactly why, but it it seems that the maintainers are not interested: #2592 (comment)

@enjoy-binbin If you want to discuss this again, I think you need to find some new information that is not already mentioned in the issue, such as a strong use case or that you have requests from users.

@madolson madolson added major-decision-approved Major decision approved by TSC team and removed major-decision-pending Major decision pending by TSC team labels Feb 2, 2026
@enjoy-binbin enjoy-binbin moved this to Needs Review in Valkey 9.1 Feb 8, 2026
@enjoy-binbin enjoy-binbin added release-notes This issue should get a line item in the release notes needs-doc-pr This change needs to update a documentation page. Remove label once doc PR is open. labels Feb 8, 2026
@ranshid

ranshid commented Feb 12, 2026

Copy link
Copy Markdown
Member

@enjoy-binbin so will we add some test for this command? or we rely only on fuzzer tests?

@enjoy-binbin

Copy link
Copy Markdown
Member Author

so will we add some test for this command? or we rely only on fuzzer tests?

I will add some tests for sure, just need some times.

enjoy-binbin added a commit to enjoy-binbin/valkey that referenced this pull request Feb 13, 2026
…ast key

This issue was encountered while processing valkey-io#3121. Currently in all our
commands with KSPEC_FK_KEYNUM, key step is 1. So this bug does not currently
affect any core commands.

If we have commands with different key step values, calculting the last key
in here will casue problems since we are not including step in the calculation.

Signed-off-by: Binbin <binloveplay1314@qq.com>
Signed-off-by: Binbin <binloveplay1314@qq.com>
Signed-off-by: Binbin <binloveplay1314@qq.com>
Comment thread tests/unit/introspection-2.tcl
Signed-off-by: Binbin <binloveplay1314@qq.com>
madolson pushed a commit that referenced this pull request Feb 23, 2026
…ast key (#3197)

This issue was encountered while processing #3121. Currently in all our
commands with KSPEC_FK_KEYNUM, key step is 1. So this bug does not
currently
affect any core commands.

If we have commands with different key step values, calculting the last
key
in here will casue problems since we are not including step in the
calculation.

Signed-off-by: Binbin <binloveplay1314@qq.com>
Signed-off-by: Binbin <binloveplay1314@qq.com>
@enjoy-binbin enjoy-binbin added the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label Feb 24, 2026

@ranshid ranshid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.
Added some small comment on the tests (which are very defensive :) )

Comment thread tests/unit/type/string.tcl
Signed-off-by: Binbin <binloveplay1314@qq.com>
@ranshid

ranshid commented Feb 25, 2026

Copy link
Copy Markdown
Member

@enjoy-binbin I am good with this version. I think we can merge it

@enjoy-binbin

Copy link
Copy Markdown
Member Author

@ranshid Thank you for the review! I myself will take a final look and review the code again this week, and then i will merge it.

@ranshid

ranshid commented Feb 25, 2026

Copy link
Copy Markdown
Member

@ranshid Thank you for the review! I myself will take a final look and review the code again this week, and then i will merge it.

ACK

Signed-off-by: Binbin <binloveplay1314@qq.com>
@enjoy-binbin

Copy link
Copy Markdown
Member Author

I think we are good to go. @valkey-io/core-team Does any of you want to take a quick final look before the merge?

Comment thread src/t_string.c Outdated
Comment thread src/t_string.c
Signed-off-by: Binbin <binloveplay1314@qq.com>
Comment thread tests/unit/type/string.tcl Outdated
@zuiderkwast

zuiderkwast commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

I don't need to review, but please fix the failing test case before merge.

Signed-off-by: Binbin <binloveplay1314@qq.com>
hpatro pushed a commit to hpatro/valkey that referenced this pull request Mar 5, 2026
…ast key (valkey-io#3197)

This issue was encountered while processing valkey-io#3121. Currently in all our
commands with KSPEC_FK_KEYNUM, key step is 1. So this bug does not
currently
affect any core commands.

If we have commands with different key step values, calculting the last
key
in here will casue problems since we are not including step in the
calculation.

Signed-off-by: Binbin <binloveplay1314@qq.com>
Signed-off-by: Harkrishn Patro <bunty.hari@gmail.com>
@ranshid

ranshid commented Mar 9, 2026

Copy link
Copy Markdown
Member

@enjoy-binbin maybe last sync with unstable would yield a cleaner test verification?

@ranshid ranshid merged commit ba58546 into valkey-io:unstable Mar 10, 2026
120 of 137 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in Valkey 9.1 Mar 10, 2026
@enjoy-binbin enjoy-binbin deleted the msetex_command branch March 11, 2026 02:28
madolson added a commit to madolson/valkey that referenced this pull request Mar 15, 2026
- Fix release date to Mon Mar 18 2026
- Fix typos: duplicate 'load', 'keyes' -> 'keys', duplicate 'INFO'
- Remove reverted contributor (arshidkv12, valkey-io#3137)
- Add 7 new release-notes entries from upstream/unstable merge:
  CLUSTERSCAN (valkey-io#2934), MSETEX (valkey-io#3121), availability-zone (valkey-io#3156),
  stream range optimization (valkey-io#3002), RDB as AOF preamble (valkey-io#1901),
  unsigned 64-bit module config (valkey-io#1546), fast_float -> ffc (valkey-io#3329)

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
JimB123 pushed a commit that referenced this pull request Mar 19, 2026
It's a combination of MSET and EXPIRE, which allows us to set an
expiration
time simultaneously with the MSET operation.

Syntax for the new MSETEX command:
```
/* MSETEX numkeys key value [key value ...] [NX | XX]
 *     [EX seconds | PX milliseconds |
 *      EXAT seconds-timestamp | PXAT milliseconds-timestamp | KEEPTTL] */
```

The MSETEX command supports a set of options (like SET command):
- EX seconds -- Set the specified expire time, in seconds (a positive
integer).
- PX milliseconds -- Set the specified expire time, in milliseconds (a
positive
  integer).
- EXAT timestamp-seconds -- Set the specified Unix time at which the
keys will
  expire, in seconds (a positive integer).
- PXAT timestamp-milliseconds -- Set the specified Unix time at which
the keys
  will expire, in milliseconds (a positive integer).
- KEEPTTL -- Retain the time to live associated with the keys.
- NX -- Only set the keys if all keys do not already exist.
- XX -- Only set the keys if all keys already exists.

Return Value (like MSETNX command):
- Integer reply: 0 if no key was set due to NX or XX options.
- Integer reply: 1 if all the keys were set.

Closes #2592

---------

Signed-off-by: Binbin <binloveplay1314@qq.com>
zuiderkwast pushed a commit to valkey-io/valkey-doc that referenced this pull request May 8, 2026
See valkey-io/valkey#3121

Signed-off-by: Binbin <binloveplay1314@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

major-decision-approved Major decision approved by TSC team needs-doc-pr This change needs to update a documentation page. Remove label once doc PR is open. release-notes This issue should get a line item in the release notes run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[NEW] MSET Command with Expiration Support

5 participants