dice icon indicating copy to clipboard operation
dice copied to clipboard

Inconsistent `APPEND`: APPEND command incorrectly resets TTL to -1

Open dankot12 opened this issue 1 year ago • 5 comments

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-cli or '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

  1. Changes in the dice code to meet the expected behavior where the TTL is preserved after the APPEND operation.
  2. 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

dankot12 avatar Oct 09 '24 02:10 dankot12

Hi @lucifercr07 @arpitbbhayani, will you please asign this issue to me?

dankot12 avatar Oct 09 '24 02:10 dankot12

Hi @apoorvyadav1111 the PR seems to be stale from sometime. Will it be fine if I pick it up?

arpit1912 avatar Oct 25 '24 05:10 arpit1912

Hi @arpit1912 , please go ahead. Thanks

apoorvyadav1111 avatar Oct 25 '24 06:10 apoorvyadav1111

Thanks @apoorvyadav1111

arpit1912 avatar Oct 26 '24 14:10 arpit1912

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

dankot12 avatar Oct 26 '24 19:10 dankot12

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

apoorvyadav1111 avatar Oct 27 '24 06:10 apoorvyadav1111

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.

arpit1912 avatar Oct 27 '24 10:10 arpit1912

@dankot12 please tag me in the PR I can take a look on the PR as well.

arpit1912 avatar Oct 27 '24 10:10 arpit1912

Hi @apoorvyadav1111, the PR is ready for your review.

@arpit1912, this is the PR - https://github.com/DiceDB/dice/pull/1037

dankot12 avatar Oct 31 '24 01:10 dankot12