GET-&-SET
GET and SET are the most fundamental commands in Valkey and Redis. They store and retrieve string values - the building blocks of your data.
You'll Learn
- Basic GET and SET syntax
- Setting expiration with EX/PX options
- Conditional SET with NX/XX flags
- How Redimo visualizes string data
See Your Data, Not Terminal Text
Redimo visualizes every Redis data type beautifully. Edit inline, undo mistakes, stay safe in production.
1. What Are GET & SET?
SET stores a string value at a key. GET retrieves it. Simple as that. These commands are the foundation of all Valkey/Redis operations.
Despite their simplicity, GET and SET are incredibly versatile. You can store anything that can be serialized to a string: plain text, numbers, JSON objects, binary data, and more. The maximum value size is 512MB, though you'll rarely need anything close to that.
Syntax
SET key value [EX seconds] [PX milliseconds] [NX|XX]
GET keySET Options
EX seconds- Set expiration in secondsPX milliseconds- Set expiration in msNX- Only set if key doesn't existXX- Only set if key exists
GET Returns
string- The value if key existsnil- If key doesn't existerror- If key holds non-string
2. The CLI Way (Hard Mode)
In the terminal, you're typing commands and reading raw text output. This works fine for simple values, but becomes a nightmare when you're storing JSON:
Simple String - Easy
127.0.0.1:6379> SET greeting "Hello, World!"
OK
127.0.0.1:6379> GET greeting
"Hello, World!"JSON String - Nightmare
127.0.0.1:6379> SET user:1001:session "{\"userId\":1001,\"token\":\"abc123\",\"expires\":1699999999,\"permissions\":[\"read\",\"write\"],\"metadata\":{\"ip\":\"192.168.1.1\",\"userAgent\":\"Mozilla/5.0\"}}"
OK
127.0.0.1:6379> GET user:1001:session
"{\"userId\":1001,\"token\":\"abc123\",\"expires\":1699999999,\"permissions\":[\"read\",\"write\"],\"metadata\":{\"ip\":\"192.168.1.1\",\"userAgent\":\"Mozilla/5.0\"}}"
127.0.0.1:6379> SET user:1001:session "..." EX 3600
OK
127.0.0.1:6379> TTL user:1001:session
(integer) 3598The Problem
3. The Redimo Way (Smart Mode)
Redimo automatically detects JSON in string values and renders it as an interactive tree view. No more escaped quotes. No more manual parsing. Just click, expand, and edit.
What Redimo Does Automatically:
- ●JSON Detection: Recognizes JSON strings and renders them as expandable tree views. Click any node to drill down.
- ●Live TTL Display: Shows remaining time right next to the key. Watch it count down in real-time.
- ●Inline Editing: Click any value to edit it directly. No need to re-type the entire SET command.
- ●TTL Preservation: When you edit a value, Redimo automatically preserves the existing TTL. No more accidentally removing expiration.
CLI Pain Points
- • Escaped JSON is completely unreadable
- • Must run TTL command separately
- • Copy-paste entire value to edit one field
- • Easy to forget EX option and lose TTL
- • No syntax highlighting for JSON
Redimo Solutions
- • JSON rendered as interactive tree
- • TTL shown inline, counts down live
- • Click to edit any nested value
- • TTL automatically preserved on edit
- • Full syntax highlighting and formatting
4. Common Patterns
GET and SET are used everywhere. Here are the most common patterns you'll encounter:
Session Storage
# Store session with 1-hour expiration
SET session:abc123 "{\"userId\":1001,\"role\":\"admin\"}" EX 3600
# Extend session on activity
EXPIRE session:abc123 3600
# Check remaining time
TTL session:abc123Distributed Locking
# Acquire lock (only if not exists)
SET lock:resource-1 "worker-42" NX EX 30
# Returns OK if acquired, nil if already locked
# Release lock (only if we own it - use Lua script in production)
GET lock:resource-1 # Check owner first
DEL lock:resource-1 # Then deleteCaching
# Cache API response for 5 minutes
SET cache:api:users:page1 "{\"users\":[...],\"total\":100}" EX 300
# Get cached value
GET cache:api:users:page1
# Refresh cache (only if exists)
SET cache:api:users:page1 "{\"users\":[...],\"total\":105}" XX EX 3005. Pro Tips
Valkey Compatibility
GETSET and GETEX
Advanced SET Options
# Set only if key doesn't exist (for locks)
SET mylock "process-1" NX EX 30
# Set only if key exists (for updates)
SET user:1001:name "Jane Doe" XX
# Get and set atomically (deprecated, use GETEX)
GETSET counter 0
# Get with expiration update (Redis 6.2+)
GETEX session:abc EX 3600
# Set multiple keys at once
MSET key1 "value1" key2 "value2" key3 "value3"
# Get multiple keys at once
MGET key1 key2 key3Redimo Bonus
Ready to Visualize?
Stop staring at escaped JSON in your terminal.
Download Redimo for free and see your data clearly.