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
-2if the key does not exist. - The command returns
-1if 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
| Engine | Throughput | p50 | p99 | p99.9 | Avg Latency |
|---|---|---|---|---|---|
| Dragonfly | 10.63M ops/s | 0.411 ms | 0.851 ms | 1.076 ms | 0.439 ms |
| Valkey | 2.33M ops/s | 2.225 ms | 2.495 ms | 2.499 ms | 2.049 ms |
| Redis | 1.94M ops/s | 2.325 ms | 2.980 ms | 3.000 ms | 2.462 ms |
Methodology
| Hardware | Server: m7g.8xlarge (arm64) · Client: c6gn.8xlarge (arm64) |
| Client | 32 threads, 5 connections, pipeline 30 |
| Dataset | 100M keys, 128B values, uniform key distribution |
| Duration | 60s (10s warmup), 1 trial |
| Measured | 2026-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.