0
0
Redisquery~5 mins

Object storage with hashes in Redis

Choose your learning style9 modes available
Introduction

Hashes let you store many related pieces of information together under one name. This keeps data organized and easy to find.

Storing user profiles with fields like name, email, and age.
Keeping product details such as price, description, and stock count.
Saving settings or preferences for an app or website.
Tracking scores or stats for players in a game.
Organizing contact information like phone number and address.
Syntax
Redis
HSET key field value [field value ...]
HGET key field
HGETALL key

HSET adds or updates fields in the hash stored at key.

HGET retrieves the value of a specific field.

HGETALL gets all fields and values in the hash.

Examples
Adds three fields to the hash named user:1000.
Redis
HSET user:1000 name "Alice" age 30 email "alice@example.com"
Gets the email field from the user:1000 hash.
Redis
HGET user:1000 email
Returns all fields and values for user:1000.
Redis
HGETALL user:1000
Sample Program

This example stores product details, then retrieves the price and all details.

Redis
HSET product:200 name "Coffee Mug" price 12.99 stock 150
HGET product:200 price
HGETALL product:200
OutputSuccess
Important Notes

Hashes are great for grouping related data without creating many keys.

Use meaningful key names to keep your data easy to manage.

HGETALL returns fields and values as a list, alternating keys and values.

Summary

Hashes store multiple fields and values under one key.

Use HSET to add or update fields, HGET to get one field, and HGETALL to get all.

This keeps related data organized and easy to access.