Skip to main content

TTL

Syntax

TTL key

Time complexity: O(1)

ACL categories: @keyspace, @read, @fast

Returns the remaining time to live of a key that has a timeout. This introspection capability allows a Dragonfly client to check how many seconds a given key will continue to be part of the dataset.

Return

Integer reply: TTL in seconds, or a negative value in order to signal an error.

  • The command returns -2 if the key does not exist.
  • The command returns -1 if the key exists but has no associated expire.

Examples

dragonfly> SET mykey "Hello"
OK
dragonfly> EXPIRE mykey 10
(integer) 1
dragonfly> TTL mykey
(integer) 10

Benchmark

Sustained throughput for TTL on a single instance, measured against Redis and Valkey on identical hardware. Higher is better.

Dragonfly10,630,000OPS
Valkey2,330,0004.6× OPS
Redis1,940,0005.5× OPS
02.75M5.5M8.25M11.0M
operations / second

Methodology

HardwareServer: m7g.8xlarge (arm64) · Client: c6gn.8xlarge (arm64)
Client32 threads, 5 connections, pipeline 30
Dataset100M keys, 128B values, uniform key distribution
Duration60s (10s warmup), 1 trial
Measured2026-07-29

Ran through dfly_bench until throughput stabilized; the reported figure is the median throughput sampled during the run. Harness and raw output: dragonflydb/benchmarking.