Keys & Strings: Overview
What is a Redis key?
Section titled “What is a Redis key?”Redis is a key–value server. Every piece of data you store — a counter, a cached page, a session token — lives under a key. Keys are binary-safe strings up to 512 MB, though in practice you should keep them short and meaningful.
A Redis value always belongs to one of the built-in types: String, List, Hash, Set, Sorted Set, Stream, and more. The String type is the simplest: a key maps directly to a single value, which can be text, a number, or raw binary.
127.0.0.1:6379> SET user:1 "Ada"OK127.0.0.1:6379> GET user:1"Ada"What this module covers
Section titled “What this module covers”| Lesson | Topic |
|---|---|
| Keys & Strings: Overview | This page — types, keys, and your first SET/GET |
| SET & GET | All SET options, MSET/MGET, APPEND, STRLEN |
| Expiration & TTL | EXPIRE, TTL, PERSIST, lazy vs active expiry |
| Counters | INCR/DECR, atomic increments, rate counters |
| SCAN & Key Ops | EXISTS, DEL, TYPE, RENAME, KEYS vs SCAN |
Your first SET and GET
Section titled “Your first SET and GET”Let’s store and retrieve a value. Paste these commands into the redis-cli you opened above:
127.0.0.1:6379> SET greeting "Hello, Redis!"OK127.0.0.1:6379> GET greeting"Hello, Redis!"SET greeting "Hello, Redis!"
GET greeting