Inconsistent `APPEND`: APPEND command incorrectly resets TTL to -1
Description
In DiceDB, the APPEND command is currently resetting the TTL (Time to Live) of a key to -1 (no expiration) instead of preserving the existing TTL. This behavior is inconsistent with Redis, where the APPEND command does not affect the TTL of a key.
When a key with a set TTL is modified using APPEND, the TTL should continue counting down as expected, without being reset. However, in DiceDB, the TTL is being removed entirely, resulting in the key remaining indefinitely.
Impact
This issue may lead to unintended key persistence when using the APPEND command on keys that are expected to expire. It affects applications that rely on key expiration for cache management, session handling, or other use cases involving TTLs.
Steps to reproduce
- Start DiceDB on port 7379.
- Run the following commands using
redis-clior 'dicedb-cli':
SET key "Hello" EX 20 # Set a key with a value and a 20-second TTL
APPEND key "World" # Append to the value
TTL key # Check the TTL after append
Expected output
The expected output when the above set of commands (maybe when run on Redis)
127.0.0.1:7379> SET key "Hello" EX 20
OK
127.0.0.1:7379> APPEND key "World"
(integer) 10
127.0.0.1:7379> TTL key
(integer) 16
Observed output
The observed output when the above set of commands when run on DiceDB
127.0.0.1:7379> SET key "Hello" EX 20
OK
127.0.0.1:7379> APPEND key "World"
(integer) 10
127.0.0.1:7379> TTL key
(integer) -1 # TTL is incorrectly reset to -1 (no expiration)
Expectations for resolution
This issue will be considered resolved when the following things are done
- Changes in the dice code to meet the expected behavior where the TTL is preserved after the APPEND operation.
- Addition of relevant test case to ensure we catch the regression
You can find the tests under the integration_tests directory of the dice repository and the steps to run are in the README file. Refer to the following links to set up DiceDB and Redis 7.2.5 locally
Hi @lucifercr07 @arpitbbhayani, will you please asign this issue to me?
Hi @apoorvyadav1111 the PR seems to be stale from sometime. Will it be fine if I pick it up?
Hi @arpit1912 , please go ahead. Thanks
Thanks @apoorvyadav1111
Hi @arpit1912 @apoorvyadav1111 , I'm already working on a PR. Would you please assign this to me? The issue is not stale as I only get time to work on open source projects on weekends
Hi @dankot12 , @arpit1912 ,Apologies for removing the assignment. Hi @arpit1912 , if you have not started working on this issue, can I please let @dankot12 continue on this one? We will be opening new issues soon. I want to ensure efforts are not wasted.
If possible, please coordinate on this issue and lets close this.
Thanks, Apoorv
Hey @dankot12 , yeahh please go ahead. Wasn't aware if you were active on the issue or not. @apoorvyadav1111 let me now if there is any other issue which I could pick.
@dankot12 please tag me in the PR I can take a look on the PR as well.
Hi @apoorvyadav1111, the PR is ready for your review.
@arpit1912, this is the PR - https://github.com/DiceDB/dice/pull/1037