HSET-&-HGET
Hash is Redis's native object type. Store user profiles, settings, and structured data without JSON serialization overhead.
You'll Learn
- HSET, HGET, HGETALL syntax
- When to use Hash vs String
- Partial updates with HINCRBY
- How Redimo renders Hash like a spreadsheet
See Your Data, Not Terminal Text
Redimo visualizes every Redis data type beautifully. Edit inline, undo mistakes, stay safe in production.
1. What Is a Hash?
A Hash is a collection of field-value pairs under a single key. Think of it as a mini-database row, a JavaScript object, or a Python dictionary. It's Redis's native way to store structured data.
Unlike storing JSON in a String, Hash lets you read and write individual fields without touching the rest. This makes partial updates efficient and atomic - perfect for user profiles, session data, or any object with multiple properties.
Syntax
HSET key field value [field value ...]
HGET key field
HGETALL key
HDEL key field [field ...]
HINCRBY key field increment
HEXISTS key field
HKEYS key
HVALS key
HLEN keyHash Advantages
- • Update single fields atomically
- • No JSON parse/stringify overhead
- • Memory efficient for small objects
- • Increment numeric fields directly
Best Use Cases
- • User profiles and settings
- • Session metadata
- • Object caching with partial updates
- • Counters grouped by entity
2. The CLI Way (Hard Mode)
Reading a hash in CLI returns alternating field-value lines. With many fields, matching them becomes a mental exercise:
Creating and Reading a Hash
127.0.0.1:6379> HSET user:1001 name "John Doe" email "john@example.com" age 28 role "admin" created_at "2024-01-15" last_login "2024-12-20" login_count 47 premium true
(integer) 8
127.0.0.1:6379> HGETALL user:1001
1) "name"
2) "John Doe"
3) "email"
4) "john@example.com"
5) "age"
6) "28"
7) "role"
8) "admin"
9) "created_at"
10) "2024-01-15"
11) "last_login"
12) "2024-12-20"
13) "login_count"
14) "47"
15) "premium"
16) "true"Reading and Updating Fields
127.0.0.1:6379> HGET user:1001 email
"john@example.com"
127.0.0.1:6379> HGET user:1001 login_count
"47"
127.0.0.1:6379> HINCRBY user:1001 login_count 1
(integer) 48
127.0.0.1:6379> HMGET user:1001 name email role
1) "John Doe"
2) "john@example.com"
3) "admin"The Problem
3. The Redimo Way (Smart Mode)
Redimo renders Hash data as an Excel-like grid. Each field is a row with its value clearly displayed. Click any cell to edit. No counting, no guessing, no mistakes.
What Redimo Does for Hashes:
- ●Spreadsheet View: Two-column layout with Field and Value. Instantly see all data without mental parsing.
- ●Inline Editing: Click any value to edit it directly. Changes are saved with a single HSET command.
- ●Add/Delete Fields: Buttons to add new fields or delete existing ones. No command typing required.
- ●Virtual Scrolling: Hash with 10,000+ fields? No problem. Virtual scrolling keeps the UI responsive.
- ●Field Search: Search within the hash to find specific fields quickly.
CLI Pain Points
- • Flat alternating list is confusing
- • Must count to match field-value pairs
- • No visual structure at all
- • Must use HGET for individual fields
- • Large hashes are impossible to scan
Redimo Solutions
- • Clear Field | Value table layout
- • Every pair on its own row
- • Click to edit any field
- • Add/delete buttons for fields
- • Virtual scrolling for large hashes
4. Hash vs JSON String
When should you use a Hash vs storing JSON in a String? Here's the decision guide:
| Criteria | Use Hash | Use JSON String |
|---|---|---|
| Partial updates | ✓ Update single fields | Read-modify-write entire JSON |
| Nested data | Only flat key-value | ✓ Deep nesting supported |
| Numeric operations | ✓ HINCRBY, HINCRBYFLOAT | Must parse and re-serialize |
| Memory (small) | ✓ ziplist encoding | Slightly more overhead |
| Arrays | Not directly supported | ✓ Native JSON arrays |
Rule of Thumb
5. Common Patterns
User Profile
# Create user profile
HSET user:1001 name "Jane Doe" email "jane@example.com" plan "pro" signup_date "2024-06-15"
# Update single field
HSET user:1001 plan "enterprise"
# Increment login count
HINCRBY user:1001 login_count 1
# Check if field exists
HEXISTS user:1001 premiumShopping Cart
# Add items to cart (field = product_id, value = quantity)
HSET cart:user:1001 product:123 2 product:456 1 product:789 3
# Update quantity
HINCRBY cart:user:1001 product:123 1
# Remove item
HDEL cart:user:1001 product:456
# Get all items
HGETALL cart:user:1001
# Count items in cart
HLEN cart:user:1001Feature Flags
# Set feature flags
HSET features:user:1001 dark_mode true beta_access true new_dashboard false
# Check single flag
HGET features:user:1001 beta_access
# Toggle flag
HSET features:user:1001 new_dashboard true
# Get all flags at once
HGETALL features:user:10016. Pro Tips
Valkey Compatibility
Useful Hash Commands
# Get list length (field count)
HLEN user:1001
# Get all field names only
HKEYS user:1001
# Get all values only
HVALS user:1001
# Get multiple specific fields
HMGET user:1001 name email role
# Check if multiple fields exist
# (Redis 7.4+) HEXISTS returns count
HEXISTS user:1001 premium beta_tester
# Increment float value
HINCRBYFLOAT user:1001 balance 10.50
# Set only if field doesn't exist
HSETNX user:1001 created_at "2024-01-01"Redimo Bonus
Ready to Visualize?
Stop counting field-value pairs in your terminal.
Download Redimo and edit Hash data like a spreadsheet.