Your First Commands
The key-value mental model
Section titled “The key-value mental model”Redis is, at its core, a key-value store. Every piece of data lives under a key. Keys are always strings. Values have a type — string, list, hash, set, sorted set, or stream — and the type determines which commands you can run on that value.
Think of it like a giant dictionary: you look up a key, you get its value. You can also ask whether a key exists, what type its value is, or delete it entirely.
SET and GET
Section titled “SET and GET”SET key value stores a value. GET key retrieves it. If the key already exists, SET overwrites it.
127.0.0.1:6379> SET name "Redis"OK127.0.0.1:6379> GET name"Redis"127.0.0.1:6379> SET score 100OKDEL — delete one or more keys
Section titled “DEL — delete one or more keys”DEL key [key ...] deletes one or more keys and returns the number of keys actually deleted. If a key does not exist, it is simply skipped and does not count toward the return value.
127.0.0.1:6379> DEL name(integer) 1127.0.0.1:6379> GET name(nil)EXISTS — check if a key exists
Section titled “EXISTS — check if a key exists”EXISTS key returns 1 if the key exists, 0 if it does not. You can pass multiple keys — the return value is the count of keys that exist.
127.0.0.1:6379> EXISTS name(integer) 1127.0.0.1:6379> EXISTS missing(integer) 0TYPE — inspect the value type
Section titled “TYPE — inspect the value type”TYPE key returns the type of the value stored at a key: string, list, hash, set, zset, or stream. It returns none if the key does not exist.
127.0.0.1:6379> TYPE namestringKEYS — list keys by pattern
Section titled “KEYS — list keys by pattern”KEYS pattern returns all keys matching a glob pattern. KEYS * matches everything.
127.0.0.1:6379> KEYS *1) "score"2) "name"WARNING: Never use
KEYS *in production. Redis is single-threaded —KEYSblocks the entire server until it has scanned every key. On a large dataset this can stall your application for seconds. UseSCANinstead, which iterates in small, non-blocking batches.
Full session walkthrough
Section titled “Full session walkthrough”Here is everything above in one continuous session:
127.0.0.1:6379> SET name "Redis"OK127.0.0.1:6379> GET name"Redis"127.0.0.1:6379> SET score 100OK127.0.0.1:6379> EXISTS name(integer) 1127.0.0.1:6379> EXISTS missing(integer) 0127.0.0.1:6379> TYPE namestring127.0.0.1:6379> KEYS *1) "score"2) "name"127.0.0.1:6379> DEL name(integer) 1127.0.0.1:6379> GET name(nil)SET name "Redis"
GET name
SET score 100
EXISTS name
EXISTS missing
TYPE name
KEYS *
DEL name
GET nameKey naming best practices
Section titled “Key naming best practices”Keys are just strings, so you can name them anything — but meaningful names make debugging and monitoring far easier. The standard convention is colon-separated namespaces:
| Pattern | Example |
|---|---|
object:id | user:42 |
object:id:field | user:42:email |
type:identifier | session:abc123 |
This makes it easy to group related keys, use glob patterns safely, and understand what a key holds at a glance in tools like RedisInsight.