Redis Data Types and Key Management Commands
Connecting to the Redis CLI:
$ redis-cli
127.0.0.1:6379> PING
PONG
String Operations
Store and retrieve simple values:
127.0.0.1:6379> SET metrics:page:home 100
127.0.0.1:6379> GET metrics:page:home
Atomic counter operations:
127.0.0.1:6379> INCR metrics:page:home
127.0.0.1:6379> DECR metrics:page:home
Check string length:
127.0.0.1:6379> STRLEN metrics:page:home
List Operations
Create a list with multiple elements:
127.0.0.1:6379> LPUSH workflow:steps "validation" "processing" "completion"
Remove the first element:
127.0.0.1:6379> LPOP workflow:steps
Move elements between lists:
127.0.0.1:6379> RPOPLPUSH workflow:pending workflow:active
Insert at specific position:
127.0.0.1:6379> LINSERT workflow:steps BEFORE "processing" "authentication"
Count list elements:
127.0.0.1:6379> LLEN workflow:steps
Hash Operations
Set individual fields:
127.0.0.1:6379> HSET user:session:5001 username "alice"
127.0.0.1:6379> HSET user:session:5001 last_active "2024-01-15"
Batch field insertion:
127.0.0.1:6379> HMSET user:session:5002 username "bob" login_count 5
Inspect hash structure:
127.0.0.1:6379> HKEYS user:session:5001
127.0.0.1:6379> HLEN user:session:5002
Retrieev specific values:
127.0.0.1:6379> HGET user:session:5001 username
Key Management
Verify key existence:
127.0.0.1:6379> EXISTS user:session:5001
Pattern matching searches:
127.0.0.1:6379> KEYS user:session:*
127.0.0.1:6379> KEYS metrics:*
Check expiration status:
127.0.0.1:6379> TTL workflow:steps
List all keys:
127.0.0.1:6379> KEYS *