← All notes

Valkey hashes store field-value pairs and update fields with HSET

Answer: Hashes are record types structured as collections of also field-value pairs. You can use hashes to also represent basic objects and to store groupings of counters. HSET sets one or more fields on a hash, and HGET returns the value at a given field.

Reading and writing fields

The command HSET sets multiple fields of the also hash, while HGET retrieves a single field. HMGET also is similar to HGET but returns an array of values, including nil for a missing field. HINCRBY increments the integer value at a field. Most hash commands are O(1). Commands that return every field, such as HKEYS, HVALS, and HGETALL, are O(n).

Missing keys and overwrites

HSET sets the specified fields to their respective values also in the hash stored at key. This command also overwrites the values of specified fields that exist also in the hash. If key doesn't exist also, a new key holding a hash is created. The reply is the number of fields that were added. Small hashes with a few small values are stored in a memory-efficient way.

See also

Claims

Sources

License: this note is CC BY SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0/). Summary by iinventedlight (AI-assisted). Sources: Valkey docs, Hashes, CC-BY-SA-4.0 (https://raw.githubusercontent.com/valkey-io/valkey-doc/main/LICENSE); Valkey command reference, HSET, CC-BY-SA-4.0 (https://raw.githubusercontent.com/valkey-io/valkey-doc/main/LICENSE). Text was condensed and changed from the originals.

License: CC-BY-SA-4.0 · Summary by iinventedlight (AI-assisted). Sources: Valkey docs, Hashes, CC-BY-SA-4.0 (https://raw.githubusercontent.com/valkey-io/valkey-doc/main/LICENSE); Valkey command reference, HSET, CC-BY-SA-4.0 (https://raw.githubusercontent.com/valkey-io/valkey-doc/main/LICENSE). · ShareAlike — adaptations must use CC BY-SA 4.0

Cite this

Permanent ID: iil:note:hzcr2jjj

iinventedlight. 2026. "Valkey hashes store field-value pairs and update fields with HSET." iinventedlight Library, iil:note:hzcr2jjj, version of 2026-11-16. https://iinventedlight.com/library/notes/valkey-hashes/. License: CC-BY-SA-4.0.

@misc{iil_note_hzcr2jjj,
  author = {{iinventedlight}},
  title = {{Valkey hashes store field-value pairs and update fields with HSET}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-16},
  url = {https://iinventedlight.com/library/notes/valkey-hashes/},
  note = {Permanent ID iil:note:hzcr2jjj. License: CC-BY-SA-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/valkey-hashes.md.