Skip to content

Keys & Strings: Overview

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"
OK
127.0.0.1:6379> GET user:1
"Ada"
LessonTopic
Keys & Strings: OverviewThis page — types, keys, and your first SET/GET
SET & GETAll SET options, MSET/MGET, APPEND, STRLEN
Expiration & TTLEXPIRE, TTL, PERSIST, lazy vs active expiry
CountersINCR/DECR, atomic increments, rate counters
SCAN & Key OpsEXISTS, DEL, TYPE, RENAME, KEYS vs SCAN

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!"
OK
127.0.0.1:6379> GET greeting
"Hello, Redis!"
SET greeting "Hello, Redis!"
GET greeting
What does the GET command return if the key does not exist?
Which of the following is a valid Redis key?
What is the maximum size of a Redis key?