Skip to content

Your First Commands

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 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"
OK
127.0.0.1:6379> GET name
"Redis"
127.0.0.1:6379> SET score 100
OK

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) 1
127.0.0.1:6379> GET name
(nil)

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) 1
127.0.0.1:6379> EXISTS missing
(integer) 0

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 name
string

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 — KEYS blocks the entire server until it has scanned every key. On a large dataset this can stall your application for seconds. Use SCAN instead, which iterates in small, non-blocking batches.

Here is everything above in one continuous session:

127.0.0.1:6379> SET name "Redis"
OK
127.0.0.1:6379> GET name
"Redis"
127.0.0.1:6379> SET score 100
OK
127.0.0.1:6379> EXISTS name
(integer) 1
127.0.0.1:6379> EXISTS missing
(integer) 0
127.0.0.1:6379> TYPE name
string
127.0.0.1:6379> KEYS *
1) "score"
2) "name"
127.0.0.1:6379> DEL name
(integer) 1
127.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 name

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:

PatternExample
object:iduser:42
object:id:fielduser:42:email
type:identifiersession: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.

What does `DEL` return?
What does `EXISTS` return for a key that does not exist?
What does `TYPE` return for a key holding a plain string value?
Why should `KEYS *` be avoided in production?