Is it possible to keep expiration/TTL when updating records? (AER-3123)



I want to use a record as a counter that expires after 20 seconds after the first increment.

Currently this is my approach:

  1. Increment the counter once en retrieve the new value
  2. If the new value is 1, I set the expiration to 20 seconds

This works correctly until i modify the record, for example by incrementing the counter. After more increments, the expiration that was set in step 2. is cleared, and the ttl from the namespace’s default expiration is used.

Is it possible to update a record while keeping the original expiration?


Currently you cannot do a write without updating the TTL. You should calculate the new TTL from what the server returned but it wouldn’t be very accurate with processing and network delays.


Would it be possible to do this with user defined functions?


Similar trick offered by @kporter would need to be exercised.

We do have AER-3123 internally to consider and track this feature request.


I know this is an old thread, but is there any news on this?

Many thanks


As of server release 3.10.1 you can set a special TTL value of -2 on your updates, which means ‘do not modify TTL’. The initial write (insert) will have whatever TTL you give it, or inherit from the namespace default TTL. Subsequent updates with TTL -2 will not modify it.


That’s great thanks @rbotzer - another quick question… use case : is it possible to create if it doesn’t exist with a TTL as specified, or update if it does exist with TTL -2 without making 2 calls… one to see “does this exist” and a second to either update or create?

Thanks again


If you’re using it across the board for upsert, the initial insert will use the default TTL for the namespace, and the subsequent updates will not touch it, meaning the record will get closer and closer to its expiration. There’s no way to give it two values from the client, but you can think about setting the right default TTL for the namespace.


We also have the following Guide with a table of the different TTL settings for server and client. Please see:


That’s great, thanks both - I guess the only way to achieve this then is to create a specific namespace for just this data in order to specify a default TTL, and then this will be unchanged by applications writing to the namespace.

Something for consideration now - thanks again

closed #11

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.