Redis Hash Management: Field-Value Based Data Structures
What will you learn in this guide?
This guide covers the Redis Hash data type in a practical way.
You learn to store multiple field–values under a single key.
You read, analyze and clean data securely.
🧠 Technical Summary
Main topic: Redis Hash (hash) data type management.
Solved problem: Organizing object-like data under a single key.
Steps: Create → query → check → delete.
1. Creating hashes and adding data
HSET is used to create the hash.
The field and value are stored under a key.
hset tr1:kullanici:01 ulke Turkiye
- This command adds a new field to the hash.
Output if the field is new:
(integer) 1
- If the field exists, the value is updated:
hset tr1:kullanici:01 ulke Almanya
- This command changes the value of the current field.
2. Just add new domain (HSETNX)
- If the field exists and you do not want it to be changed, HSETNX is used.
hsetnx tr1:kullanici:01 ulke Turkiye
- If the field already exists, no action is taken and 0 is returned.
3. Add multiple fields
- HMSET is used to add multiple fields in a single operation.
hmset tr1:kullanici:01 dogum 1990 meslek Yazilimci kategori Uzman
- This command adds multiple fields into the hash.
4. Reading data from hash
- HGET is used to read a single field.
hget tr1:kullanici:01 meslek
- This command returns the value of the field.
- To read multiple fields:
hmget tr1:kullanici:01 dogum meslek
- This command lists multiple values.
5. List fields and values
- To get domain names:
hkeys tr1:kullanici:01
- This command lists all fields.
- To get the values:
hvals tr1:kullanici:01
- This command lists all values.
- To get fields and values together:
hgetall tr1:kullanici:01
- This command returns the exact hash content.
6. Checking if there is space
- To check if a field is in the hash:
hexists tr1:kullanici:01 ulke
- Returns 1 if the field exists, 0 otherwise.
7. Getting information about hash
- To find out the number of fields:
hlen tr1:kullanici:01
- This command returns the number of fields in the hash.
To measure the length of the field value:
hstrlen tr1:kullanici:01 meslek
- This command returns the value length in characters.
8. Area wiping and cleaning
- HDEL is used to delete area.
hdel tr1:kullanici:01 dogum meslek
-
This command removes the specified fields from the hash.
-
Redis does not give an error if the field does not exist.
Frequently Asked Questions (FAQ)
1. Should I use Hash or String? Hash is more suitable for multi-field data.
2. How many fields can be in the hash? Redis hash structures support very large field numbers.
3. Is hgetall risky for large hashes? Yes. HSCAN should be preferred in large buildings.
4. How to delete the hash completely? The key is removed with the DEL command.
Result
You have created regular data models with the Redis Hash data type. You have provided high-performance storage with the field-value structure. You've learned the right commands for big data.
For high-performance Redis infrastructures, you can try it now on the GenixNode platform.

