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
- id: C1 claim: Valkey hashes are collections of field-value pairs. source: S1 evidence: "Hashes are record types structured as collections of field-value pairs."
- id: C2 claim: HSET can set multiple fields of a hash in one command. source: S1 evidence: "The command HSET sets multiple fields of the hash"
- id: C3 claim: HSET overwrites values of fields that already exist in the hash. source: S2 evidence: "This command overwrites the values of specified fields that exist in the hash."
- id: C4 claim: If the key does not exist, HSET creates a new hash at that key. source: S2 evidence: "If key doesn't exist, a new key holding a hash is created."
Sources
- [S1] Hashes. Valkey docs. https://valkey.io/topics/hashes/ . License: CC-BY-SA-4.0. Accessed 2026-11-16.
- [S2] HSET. Valkey command reference. https://valkey.io/commands/hset/ . License: CC-BY-SA-4.0. Accessed 2026-11-16.
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
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.},
}
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.