{
  "id": 6726858,
  "title": "Valkey 9.1's hash field TTL triples memory use for the pattern its own docs show",
  "url": "https://urgent.news/2026/09/11/valkey-9-1s-hash-field-ttl-triples-memory-use-for-the-pattern-its-own",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-11T08:00:00.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/alexgeorgiev17/valkey-91s-hash-field-ttl-triples-memory-use-for-the-pattern-its-own-docs-show-22k8"
  },
  "original_language": "en",
  "account": "The Valkey 9.1 update introduces a hash field TTL feature that can triple memory usage when compared to the simpler pattern of using EXPIRE on a plain string key. The Valkey blog post demonstrates this with an example of a per-user auth token stored as a field inside a hash, using HSETEX to set both the field and its TTL in one round trip. However, the memory impact is significant: a hash per item with an expiring field TTL (HSETEX) uses 261.33 bytes per key, compared to 87.74 bytes per key for a hash without TTL (HSET) and 86.68 bytes per key for a plain string key with EXPIRE. This means the hash version with a single TTL field costs almost exactly three times as much memory as the plain string version. The extra memory usage is not due to the TTL feature itself, but rather the switch from listpack encoding to hashtable encoding when a single field is given a TTL. This change occurs regardless of how few fields the hash has or how small they are. The documentation shows an example of one hash per item with a single field carrying a TTL, which is not the optimal shape for this feature. A better approach is to use one hash with 20,000 fields, each set through HSETEX with its own TTL. In this case, the memory difference is only 23.44 bytes per field, which is the actual cost of tracking an expiry. The TTL feature does not degrade normal hash operations, as benchmarked reads show no measurable difference between hashes with and without field TTLs. However, there are a few error paths to be aware of, such as operations against a key with the wrong value type or invalid expire times. Overall, the Valkey 9.1 field TTL feature provides cheap per-field TTLs on a shared structure, but the memory cost should be considered when deciding whether to use this feature or stick with the simpler plain string key with EXPIRE.",
  "summary": "Valkey 9.0 added the ability to put a TTL on a single field inside a hash, rather than on the whole key. Valkey 9.1 followed up with HSETEX , which sets a field and its expiry in one round trip. The example in Valkey's own blog post is a per-user auth token: HSETEX user:123 EX 900 FIELDS 1 auth_token \"eyJhbGciOiJ...\" That reads like a drop-in replacement for SET user:123:auth_token \"...\" EX 900 .…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}