The problem/use-case that the feature addresses
Currently, there is no single Valkey command that allows setting multiple keys with expiration in one atomic operation. Users who need to set multiple keys with the same TTL must resort to workarounds that have significant performance and reliability drawbacks.
Current Workarounds and Their Limitations:
Approach 1: Pipelining (MSET + Multiple EXPIRE), this will still increase the oneway network round-trip overhead.
MULTI
MSET key1 val1 key2 val2 key3 val3
EXPIRE key1 300
EXPIRE key2 300
EXPIRE key3 300
EXEC
Approach 2: Lua Scripting, scripts must access keys in single slot (without cross-slot capability)
local keys = KEYS
local values = ARGV
local ttl = tonumber(ARGV[1])
for i = 1, #keys do
redis.call('SET', keys[i], values[i+1])
redis.call('EXPIRE', keys[i], ttl)
end
return "OK"
Approach 3: Individual SET Commands with Expiration, lack of atomicity
# Sequential SET commands
SET key1 val1 EX 300
SET key2 val2 EX 300
SET key3 val3 EX 300
Description of the feature
Enhance MSET command to supports atomic setting of multiple key-value pairs with optional expiration, providing a more efficient alternative to using MSET followed by multiple EXPIRE commands.
MSET key value [key value ...] [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds]
Parameters
key value: One or more key-value pairs to set
EX seconds: Set expiration time in seconds (relative)
PX milliseconds: Set expiration time in milliseconds (relative)
EXAT unix-time-seconds: Set expiration time as Unix timestamp in seconds (absolute)
PXAT unix-time-milliseconds: Set expiration time as Unix timestamp in milliseconds (absolute)
Note: Only one expiration option can be specified per command.
Advantages of Enhanced MSET Approach
Single Network Round-Trip
- Dramatic Latency Reduction: Only one command to send and acknowledge
- Bandwidth Efficiency: Minimal protocol overhead compared to multiple commands
- Connection Efficiency: Reduced connection pool pressure
Optimized Server-Side Processing
- Atomic Execution Path: Single code path handles both setting and expiration
- Memory Locality: All operations happen in single function call stack
- Cache Efficiency: Better CPU cache utilization for batch operations
Reduced Replication Overhead
- Compact Replication: Single command replication instead of multiple
- Faster Replica Sync: Less data to transmit to replicas
- Lower AOF Size: More compact persistence format
Alternatives you've considered
Backward Compatibility
The enhanced MSET command is fully backward compatible:
- Existing MSET commands without expiration options work unchanged
- No breaking changes to command behavior
- Maintains the same performance characteristics for non-expiration usage
Additional information
If the issue is accepted, we would like deliver this enhancement .
The problem/use-case that the feature addresses
Currently, there is no single Valkey command that allows setting multiple keys with expiration in one atomic operation. Users who need to set multiple keys with the same TTL must resort to workarounds that have significant performance and reliability drawbacks.
Current Workarounds and Their Limitations:
Approach 1: Pipelining (MSET + Multiple EXPIRE), this will still increase the oneway network round-trip overhead.
Approach 2: Lua Scripting, scripts must access keys in single slot (without cross-slot capability)
Approach 3: Individual SET Commands with Expiration, lack of atomicity
Description of the feature
Enhance
MSETcommand to supports atomic setting of multiple key-value pairs with optional expiration, providing a more efficient alternative to using MSET followed by multiple EXPIRE commands.MSET key value [key value ...] [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds]Parameters
key value: One or more key-value pairs to set
EX seconds: Set expiration time in seconds (relative)
PX milliseconds: Set expiration time in milliseconds (relative)
EXAT unix-time-seconds: Set expiration time as Unix timestamp in seconds (absolute)
PXAT unix-time-milliseconds: Set expiration time as Unix timestamp in milliseconds (absolute)
Note: Only one expiration option can be specified per command.Advantages of Enhanced MSET Approach
Single Network Round-Trip
Optimized Server-Side Processing
Reduced Replication Overhead
Alternatives you've considered
Backward Compatibility
The enhanced MSET command is fully backward compatible:
Additional information
If the issue is accepted, we would like deliver this enhancement .