garnet icon indicating copy to clipboard operation
garnet copied to clipboard

The `PX` command does not seem to be supported

Open y1jiong opened this issue 1 year ago • 2 comments

Hi, The PX command does not seem to be supported.

Garnet reports ERR unknown command when I am using SET k1 v1 PX 10000.

y1jiong avatar Mar 21 '24 12:03 y1jiong

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 NetworkSETEXNX in https://github.com/microsoft/garnet/blob/main/libs/server/Resp/BasicCommands.cs
  • Add an if for [PX] similar to [EX] at https://github.com/microsoft/garnet/blob/main/libs/server/Resp/BasicCommands.cs#L470
  • Set a local bool highPrecision to true if [PX] is specified
  • Take highPrecision as argument to NetworkSET_EX and NetworkSET_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

badrishc avatar Mar 21 '24 14:03 badrishc

As workaround, you can use PSETEX which is implemented.

badrishc avatar Mar 21 '24 15:03 badrishc