garnet
garnet copied to clipboard
The `PX` command does not seem to be supported
Hi,
The PX command does not seem to be supported.
Garnet reports ERR unknown command when I am using SET k1 v1 PX 10000.
Correct, this was not added due to lack of interest in the past. Should be an easy extension to the existing SET logic. Contributions welcome!
Basic idea:
- Edit
NetworkSETEXNXin https://github.com/microsoft/garnet/blob/main/libs/server/Resp/BasicCommands.cs - Add an
iffor [PX] similar to [EX] at https://github.com/microsoft/garnet/blob/main/libs/server/Resp/BasicCommands.cs#L470 - Set a local bool
highPrecisiontotrueif [PX] is specified - Take
highPrecisionas argument toNetworkSET_EXandNetworkSET_Conditional - Change https://github.com/microsoft/garnet/blob/main/libs/server/Resp/BasicCommands.cs#L612 and https://github.com/microsoft/garnet/blob/main/libs/server/Resp/BasicCommands.cs#L646 to handle
highPrecision. It would be something like:SpanByte.Reinterpret(inputPtr).ExtraMetadata = DateTimeOffset.UtcNow.Ticks + (highPrecision ? TimeSpan.FromMilliseconds(expiry).Ticks : TimeSpan.FromSeconds(expiry).Ticks). - Add a unit test in
RespTests.cs
As workaround, you can use PSETEX which is implemented.